Hi, I'm a newby of AHK.
I'd try to modify the script (with the italian recognizer engine) to fire some CAD commands by voice.
But when I run the script I see the commands in the CAD to become random (when I say "rettangolo" starts the command "cerchio" and so on).
Thank you a lot.
Code: Select all
#SingleInstance force
#Persistent
; Load the HotVoice Library
#include Lib\HotVoice.ahk
; Create a new HotVoice class
hv := new HotVoice()
recognizers := hv.GetRecognizerList()
Gui, Add, Text, xm w600 Center, Riconoscimento vocale disponibile
Gui, Add, ListView, xm w600 r5 hwndhRecognizerId -Multi, ID|Name|Code|Language
Loop % recognizers.Length(){
rec := recognizers[A_index]
if (rec.TwoLetterISOLanguageName == "iv")
continue ; Invariant language culture does not seem to be supported
LV_Add(, rec.Id, rec.Name, rec.TwoLetterISOLanguageName, rec.LanguageDisplayName)
}
LV_ModifyCol(1, 30)
LV_ModifyCol(2, 350)
LV_ModifyCol(3, 40)
LV_ModifyCol(4, 155)
LV_Modify(1, "Select")
Gui, Add, Button, Center w600 gLoadRecognizer, Scegli il riconoscimento vocale`n(Languages supported by this demo: it)
Gui, Add, Text, xm w600 Center, Comandi Disponibili
Gui, Add, ListView, xm w600 r10 hwndhAvailableCommands, programma|Comandi
Gui, Add, Text, xm Center w600, Mic Volume
Gui, Add, Slider, xm w600 hwndhSlider
Gui, Add, Text, xm Center w600, Output
Gui, Add, Edit, hwndhOutput w600 r5 vhwndhOutput
LV_ModifyCol(1, 125)
Gui, Show, , HotVoice Demo
return
LoadRecognizer:
; Initialize HotVoice and tell it what ID Recognizer to use
Gui, ListView, % hRecognizerId
if (LV_GetCount() == 0){
UpdateOutput("No supported languages found")
return
}
recognizer := GetCurrentRecognizer()
Gui, ListView, % hAvailableCommands
LV_Delete()
LV_Add(, hv.LoadGrammar(contactGrammar, Func("LogWords")))
if (recognizer.TwoLetterISOLanguageName == "it"){
; ==== italiano ====
hv.Initialize(recognizer.Id)
; -------- comanndi di allplan ------------
contactGrammar := hv.NewGrammar()
maleGrammar := hv.NewGrammar()
maleChoices := hv.NewChoices("cancella fra estremi,modifica punti,parallela,linea,cerchio,rettangolo")
maleGrammar.AppendChoices(maleChoices)
contactGrammar.AppendGrammars(maleGrammar)
LV_Add(, "Allplan", hv.LoadGrammar(contactGrammar, "", Func("LogWords")))
} else {
UpdateOutput("Language " recognizer.TwoLetterISOLanguageName " is not supported by this demo")
return
}
; Monitor the volume
hv.SubscribeVolume(Func("OnMicVolumeChange"))
LogRecognizerLoad(recognizer)
hv.StartRecognizer()
return
LogRecognizerLoad(recognizer){
;UpdateOutput("Loading Recognizer ID:" recognizer.Id ", Code: " recognizer.TwoLetterISOLanguageName ", Name: " recognizer.LanguageDisplayName)
}
GetCurrentRecognizer(){
global recognizers, hRecognizerId
Gui, ListView, % hRecognizerId
return recognizers[LV_GetNext()]
}
OnMicVolumeChange(state){
global hSlider
GuiControl, , % hSlider, % state
}
;Log out recognized words
LogWords(grammarName, words){
UpdateOutput(grammarName " " Join(words))
}
; Join array of words into sentence
Join(arr){
for i, w in arr {
str .= w " "
}
return str
}
UpdateOutput(text){
global hOutput
static WM_VSCROLL = 0x115
static SB_BOTTOM = 7
Gui, +HwndhGui
; Get old text
;GuiControlGet, t, , % hOutput
;~ t .= text " @ " A_Now "`n"
t .= text
GuiControl, , % houtput, % t
; Scroll box to end
PostMessage, WM_VSCROLL, SB_BOTTOM, 0, Edit1, ahk_id %hGui%
if (t= rettangolo)
msgbox, rettangolo
send, ^!y::^!y
if (t= cerchio)
msgbox, cerchio
send, ^k::^k
if (t= parallela)
msgbox, parallela
send, ^p::^p
}
;^Esc::
GuiClose:
;ExitApp