HotVoice - Speech Recognition + Volume detection for AHK (C# DLL)

Post your working scripts, libraries and tools
kevlea
Posts: 1
Joined: 06 Aug 2020, 13:13

Re: HotVoice - Speech Recognition + Volume detection for AHK (C# DLL)

Post by kevlea » 06 Aug 2020, 13:24

Is it possible to hotkeys combined with hotvoice calling functions? I have been able to get hotvoice to call functions but not to toggle autohotkey

Code: Select all

#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)
kl4Grammar := hv.NewGrammar()
kl4Grammar.AppendString("F-escape")
hv.LoadGrammar(kl4Grammar, "F-escape", Func("myEsc"))
hv.StartRecognizer()

myEsc(){
Suspend, Toggle
Return
}


Duttebayo
Posts: 1
Joined: 04 Sep 2020, 13:40

Re: HotVoice - Speech Recognition + Volume detection for AHK (C# DLL)

Post by Duttebayo » 04 Sep 2020, 14:07

Is it possible for the Recognizer to have multiple starting points?

From what i have understood, the grammar and choices help formulate a sentence like command. But consider the following codec:

Code: Select all

hv := new HotVoice()
hv.Initialize(0)
menuGrammar := hv.NewGrammar()
menuGrammar.AppendString("Switch-Window")
; menuGrammar.AppendString("New-Window")

windowChoices := hv.NewChoices("Chrome,Explorer,Premiere,Word,Whatsapp")
menuGrammar.AppendChoices(windowChoices)
hv.LoadGrammar(menuGrammar, "Switch-Window", Func("SwitchWindow"))
; hv.LoadGrammar(menuGrammar, "New-Window", Func("NewWindow"))
hv.StartRecognizer()
[Mod edit: [code][/code] tags added.]

Here i desire to call out routines to either switch between windows or launch a new window based on the first voice command.
Similarly, in the same ahk script i wish to enumerate the following command chains
--> Switch Window + Chrome/Explorer/Premiere/Word/Whatsapp
--> New Window + Chrome/Explorer/Premiere/Word/Whatsapp
--> Switch Tabs + Notepad/Chrome/Firefox
and so on..

Is it possible for me to utilize the same HotVoice object for multiple grammars?
I have tried it but was unsuccessful. Utilizing 2 different HotVoice objects does the trick but if i were to expand the script to say 20 unique command "chains", creating 20 different objects would be annoying.

Am i doing something wrong here. Any word of advice?


PS: this is purely an educational project to grasp the reach of HotVoice.
PPS: Thank you for all your work on this. This library is amazing.

User avatar
evilC
Posts: 4787
Joined: 27 Feb 2014, 12:30

Re: HotVoice - Speech Recognition + Volume detection for AHK (C# DLL)

Post by evilC » 04 Sep 2020, 15:06

Demo.ahk demonstrates exactly this - two completely separate grammars - "Volume" and "Call Contact", both using the same hotvoice object

Code: Select all

volumeGrammar := hv.NewGrammar()
;...
contactGrammar := hv.NewGrammar()
; ...

scriptor2016
Posts: 689
Joined: 21 Dec 2015, 02:34

Re: HotVoice - Speech Recognition + Volume detection for AHK (C# DLL)

Post by scriptor2016 » 29 Oct 2020, 23:30

I thought HotVoice wasn't working on my system because I'm running Windows 7. So I installed it on my Windows 10 laptop... and wouldn't you know it, exact same error: Hotvoice.dll failed to load....

still baffled by this, I don't know how everyone else got this to work :(

iuppiterone
Posts: 9
Joined: 01 Nov 2020, 11:56

Re: HotVoice - Speech Recognition + Volume detection for AHK (C# DLL)

Post by iuppiterone » 06 Nov 2020, 02:11

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).
How can I manage this problem?
Thank you a lot.

here the script modificated:

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
[Mod edit: [code][/code] tags added.]


scriptor2016
Posts: 689
Joined: 21 Dec 2015, 02:34

Re: HotVoice - Speech Recognition + Volume detection for AHK (C# DLL)

Post by scriptor2016 » 07 Nov 2020, 02:28

SUCCESS

This might make me look stupid (lol), but somehow I was running the 32-bit version of AHK. That was the only problem here. Soon as I upgraded to the 64-bit, it worked right away. So yes, I can confirm this works on Windows 7, but it must be the 64-bit version of AHK.

I've tried a few different words and phrases, but unfortunately it looks like this script suffers the same problem as most of the other voice-recognition scripts: the recognition is just not working properly. But I think this has to do with Microsoft, and NOT hotvoice. I have several other AHK voice recognition scripts, and they all act the same way. It seems to be totally random whenever you say a word. It might pick it up, it might not, or it might interpret the word as something totally different. For example, you say "banana" and it thinks you said "apple".

I've tried a few similar words in the code below, and it's just randomly interpreting any of the available words. If I say "Layer", it might interpret it as "delete layer" or maybe as "new layer", even though the command "Layer" (on its own) doesn't exist.

Hotvoice is definitely the best of the bunch, but Microsoft's voice recognition is totally hopeless in this case.

I'll post my code just for the heck of it:

Code: Select all

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

#include Lib\HotVoice.ahk


hv := new HotVoice()
hv.Initialize(0)
testGrammar := hv.NewGrammar()
testGrammar.AppendString("new layer")
hv.LoadGrammar(testGrammar, "new layer", Func("MyFunc"))
hv.StartRecognizer()
 

hv := new HotVoice()
hv.Initialize(0)
testGrammar := hv.NewGrammar()
testGrammar.AppendString("new layer down")
hv.LoadGrammar(testGrammar, "new layer down", Func("MyFunc"))
hv.StartRecognizer()


hv := new HotVoice()
hv.Initialize(0)
testGrammar := hv.NewGrammar()
testGrammar.AppendString("delete layer")
hv.LoadGrammar(testGrammar, "delete layer", Func("MyFunc"))
hv.StartRecognizer()


hv := new HotVoice()
hv.Initialize(0)
testGrammar := hv.NewGrammar()
testGrammar.AppendString("rename layer")
hv.LoadGrammar(testGrammar, "rename layer", Func("MyFunc"))
hv.StartRecognizer()


hv := new HotVoice()
hv.Initialize(0)
testGrammar := hv.NewGrammar()
testGrammar.AppendString("send layer to top")
hv.LoadGrammar(testGrammar, "send layer to top", Func("MyFunc"))
hv.StartRecognizer()

Return







MyFunc(grammarName, words)
{
tooltip, %grammarName%

if grammarName = new layer
{
tooltip new layer
}

if grammarName = new layer down
{
tooltip, new layer down
}

if grammarName = delete layer
{
tooltip, delete layer
}

if grammarName = rename layer
{
tooltip, rename layer
}

if grammarName = send layer to top
{
tooltip, send layer to top
}

}


iuppiterone
Posts: 9
Joined: 01 Nov 2020, 11:56

Re: HotVoice - Speech Recognition + Volume detection for AHK (C# DLL)

Post by iuppiterone » 07 Nov 2020, 04:57

evilC wrote:
06 Nov 2020, 06:56
You need quotes around those words
if if (t= "rettangolo")
I tried but doesn't work.
Maybe on modifying your script I deleted or disabled something important.

It would be great if you could send me a simplest version:
I need not phrases or grammar, but only a list of italian words able to fire some shortcuts in an external program.

I really need this stuff because of a degenerative illness I'm suffering that make me very difficult using keyboards.
I hope you kindly could help me.

thanks a lot

Max

iuppiterone
Posts: 9
Joined: 01 Nov 2020, 11:56

Re: HotVoice - Speech Recognition + Volume detection for AHK (C# DLL)

Post by iuppiterone » 08 Nov 2020, 03:57

scriptor2016 wrote:
07 Nov 2020, 02:28
SUCCESS

This might make me look stupid (lol), but somehow I was running the 32-bit version of AHK. That was the only problem here. Soon as I upgraded to the 64-bit, it worked right away. So yes, I can confirm this works on Windows 7, but it must be the 64-bit version of AHK.

I've tried a few different words and phrases, but unfortunately it looks like this script suffers the same problem as most of the other voice-recognition scripts: the recognition is just not working properly. But I think this has to do with Microsoft, and NOT hotvoice. I have several other AHK voice recognition scripts, and they all act the same way. It seems to be totally random whenever you say a word. It might pick it up, it might not, or it might interpret the word as something totally different. For example, you say "banana" and it thinks you said "apple".

I've tried a few similar words in the code below, and it's just randomly interpreting any of the available words. If I say "Layer", it might interpret it as "delete layer" or maybe as "new layer", even though the command "Layer" (on its own) doesn't exist.

Hotvoice is definitely the best of the bunch, but Microsoft's voice recognition is totally hopeless in this case.

I'll post my code just for the heck of it:

Code: Select all

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

#include Lib\HotVoice.ahk


hv := new HotVoice()
hv.Initialize(0)
testGrammar := hv.NewGrammar()
testGrammar.AppendString("new layer")
hv.LoadGrammar(testGrammar, "new layer", Func("MyFunc"))
hv.StartRecognizer()
 

hv := new HotVoice()
hv.Initialize(0)
testGrammar := hv.NewGrammar()
testGrammar.AppendString("new layer down")
hv.LoadGrammar(testGrammar, "new layer down", Func("MyFunc"))
hv.StartRecognizer()


hv := new HotVoice()
hv.Initialize(0)
testGrammar := hv.NewGrammar()
testGrammar.AppendString("delete layer")
hv.LoadGrammar(testGrammar, "delete layer", Func("MyFunc"))
hv.StartRecognizer()


hv := new HotVoice()
hv.Initialize(0)
testGrammar := hv.NewGrammar()
testGrammar.AppendString("rename layer")
hv.LoadGrammar(testGrammar, "rename layer", Func("MyFunc"))
hv.StartRecognizer()


hv := new HotVoice()
hv.Initialize(0)
testGrammar := hv.NewGrammar()
testGrammar.AppendString("send layer to top")
hv.LoadGrammar(testGrammar, "send layer to top", Func("MyFunc"))
hv.StartRecognizer()

Return







MyFunc(grammarName, words)
{
tooltip, %grammarName%

if grammarName = new layer
{
tooltip new layer
}

if grammarName = new layer down
{
tooltip, new layer down
}

if grammarName = delete layer
{
tooltip, delete layer
}

if grammarName = rename layer
{
tooltip, rename layer
}

if grammarName = send layer to top
{
tooltip, send layer to top
}

}



Yes, I suspected there was a windows recognizer problem as well.
I think that SAPI are even worse.
Dragon is great but you have to install an elephant- like software, very expensive and non-portable.
How do you think to manage the problem?
Perhaps Google API? ( But I dont want to learn other languages such as Pithon...)

Max

scriptor2016
Posts: 689
Joined: 21 Dec 2015, 02:34

Re: HotVoice - Speech Recognition + Volume detection for AHK (C# DLL)

Post by scriptor2016 » 08 Nov 2020, 14:03

Agreed. I use Dragon Naturally as well and yes, it is a huge program with way too many features I never use.

I just wanted a small, portable voice recognition software where I can speak quick commands.

Hotvoice is perfect. I also have a couple of other AHK voice recognition scripts which are good as well, but all of them suffer from the same problem with the Windows recognizer. It's useless.

The only other option might be to look at some other smaller voice recognition programs out there. Or, stick with Dragon. It' the best one but it is so big and uses so many resources!

Post Reply

Return to “Scripts and Functions”