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

Post your working scripts, libraries and tools for AHK v1.1 and older
kevlea
Posts: 1
Joined: 06 Aug 2020, 13:13

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

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)

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: 4822
Joined: 27 Feb 2014, 12:30

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

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: 844
Joined: 21 Dec 2015, 02:34

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

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: 23
Joined: 01 Nov 2020, 11:56

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

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: 844
Joined: 21 Dec 2015, 02:34

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

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: 23
Joined: 01 Nov 2020, 11:56

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

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: 23
Joined: 01 Nov 2020, 11:56

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

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: 844
Joined: 21 Dec 2015, 02:34

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

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!
User avatar
submeg
Posts: 326
Joined: 14 Apr 2017, 20:39
Contact:

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

16 Feb 2021, 05:26

hey @evilC,

Giving this another go as per your suggestion on reddit.I tried to use the unblock powershell, but no good! I copied the single line into a powershell session (running as admin) and I received the following error - see image.

Some info:

I run two accounts on my PC - an admin account and a standard user account. I work mainly in the standard account, and that was the one I was doing all of this in. Is this the cause of the error above? Even though I was able to run Powershell as admin, but it wasn't happy. I even logged into my admin account again and tried this as well, but still no good. I even went in and made sure I had the right access level set to run the powershell script enabled.
____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:
superpeter
Posts: 115
Joined: 18 Dec 2020, 05:17

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

21 Feb 2021, 00:51

Really interesting! I'm thinking of developing another approach to dictating voice commands and I'd love to hear feedback.

Basically, I would simply use the inputbox and Dragon NaturallySpeaking in order to utter keywords or expressions.

Then, the script would search for keywords in the string and if present, it would launch actions associated with the keywords.

For example, using Dragon, I could say "launch AI project" and "open Facebook" and the script, having recognized these expression (using RegExMatch) would 1. open all files related to my AI project and 2. launch the Facebook website.
valentin21
Posts: 1
Joined: 28 Feb 2021, 15:31

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

28 Feb 2021, 15:42

scriptor2016 wrote:
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 :(
Hello,

Can you help me with the installation of the components needed for this to work?
From the initial post the "Microsoft Speech Platform Runtime" is no longer available.
I use Windows 10 - 64 bit, Ahk 64 bit.

Thank you.
gregster
Posts: 8916
Joined: 30 Sep 2013, 06:48

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

28 Feb 2021, 15:50

valentin21 wrote:
28 Feb 2021, 15:42
Hello,

Can you help me with the installation of the components needed for this to work?
From the initial post the "Microsoft Speech Platform Runtime" is no longer available.
I use Windows 10 - 64 bit, Ahk 64 bit.

Thank you.
IHuh, it seems Microsoft updated that component this month, on Feb 10 - and changed the link.
(I just downloaded the old one a few days before the update...)

I guess the new link is now this: https://www.microsoft.com/en-us/download/details.aspx?id=16789
And language packs probably this: https://www.microsoft.com/en-us/download/details.aspx?id=24139

But I haven't tried the new ones...
scriptor2016
Posts: 844
Joined: 21 Dec 2015, 02:34

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

03 Mar 2021, 00:55

superpeter wrote:
21 Feb 2021, 00:51
Really interesting! I'm thinking of developing another approach to dictating voice commands and I'd love to hear feedback.

Basically, I would simply use the inputbox and Dragon NaturallySpeaking in order to utter keywords or expressions.

Then, the script would search for keywords in the string and if present, it would launch actions associated with the keywords.

For example, using Dragon, I could say "launch AI project" and "open Facebook" and the script, having recognized these expression (using RegExMatch) would 1. open all files related to my AI project and 2. launch the Facebook website.
Or another way:

Create and train a new voice command ("Command One" for example)

Then set it to "Open(Application)" and select an AHK script for it to run.

Then, whenever you say "Command One", it will run that script.
superpeter
Posts: 115
Joined: 18 Dec 2020, 05:17

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

03 Mar 2021, 01:54

Thanks @scriptor2016, good idea! I think we can create up to a thousand voice commands in Dragon NaturallySpeaking, if I remember correctly.
D4ng_kun
Posts: 11
Joined: 06 Jun 2021, 23:32

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

25 Jun 2021, 03:10

gregster wrote:
28 Feb 2021, 15:50
valentin21 wrote:
28 Feb 2021, 15:42
Hello,

Can you help me with the installation of the components needed for this to work?
From the initial post the "Microsoft Speech Platform Runtime" is no longer available.
I use Windows 10 - 64 bit, Ahk 64 bit.

Thank you.
IHuh, it seems Microsoft updated that component this month, on Feb 10 - and changed the link.
(I just downloaded the old one a few days before the update...)

I guess the new link is now this: https://www.microsoft.com/en-us/download/details.aspx?id=16789
And language packs probably this: https://www.microsoft.com/en-us/download/details.aspx?id=24139

But I haven't tried the new ones...
It seems like both link were removed..
Can hotvoice run without both the Runtime and language Pack ? I am on Window 10 64bit
gregster
Posts: 8916
Joined: 30 Sep 2013, 06:48

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

25 Jun 2021, 03:48

D4ng_kun wrote:
25 Jun 2021, 03:10
It seems like both link were removed..
Can hotvoice run without both the Runtime and language Pack ? I am on Window 10 64bit
I doubt it.
No idea where MS put the components - sorry, I can't find them at the moment.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 91 guests