Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Understanding Grammar and Choices #7

Open
Laanan opened this issue Nov 1, 2022 · 1 comment
Open

Understanding Grammar and Choices #7

Laanan opened this issue Nov 1, 2022 · 1 comment

Comments

@Laanan
Copy link

Laanan commented Nov 1, 2022

Hi there,

I am tinkering around with some initial scripting with Hot Voice and want to make sure I am understanding how it works. First script is to set a voice controlled volume up and volume down command, and I am using the Choices script as a template...I am aiming for the user to be able to say "Volume Up" to raise the volume and "Volume Down" to lower it. Later I am to add things like "Open Sesame" to open one app and "Open Banana" to open another.

It looks like grammar pieces are added to an array, and then choices are appended to that array. Does Hot Voice take the first input as item [0], and then wait for any further inputs [1,2,3,n], or do I need to make a function with conditionals that takes the inputs and checks them/parses them, like:

if "volume" --> if "up" --> do this; else if "down" --> do that

or, a bit closer to the actual syntax:

if (grammar[0] == "Volume") {
if (grammar[1] == "Up") {
SetSound, +5
}
else if (grammar[1] == "Down") {
SetSound, -5
}
else {
break
}
}

Something like that?

@evilC
Copy link
Owner

evilC commented Nov 3, 2022

Something like

#SingleInstance force
#Persistent ; You will need this if your script creates no hotkeys or has no GUI

; Load the HotVoice Library
#include Lib\HotVoice.ahk

; Create a new HotVoice class
hv := new HotVoice()

; Initialize HotVoice and tell it what ID Recognizer to use
hv.Initialize(0)

; Create a new Grammar
testGrammar := hv.NewGrammar()
testGrammar.AppendString("Volume")

; Create a new Choices object with up / down choices
upDownChoices := hv.NewChoices("up, down")

; Add the choices to the Grammar
volumeGrammar.AppendChoices(upDownChoices)

; Load the Grammar
hv.LoadGrammar(volumeGrammar, "Volume", Func("VolumeFunc"))

hv.StartRecognizer()

return

VolumeFunc(grammarName, words){
	if (words[2] == "up"){
		SetSound, +5
	} else if (words[2] == "down) {
		SetSound, -5
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants