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

Post your working scripts, libraries and tools for AHK v1.1 and older
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

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

02 Jun 2018, 11:31

I tried the CultureOptimize DLL, getting this error still:
[deleted]
EDIT: Error gone, so I deleted it. I restarted, and all was well.
I really appreciate you taking the time and effort for this, by the way, thanks.
Just a note: It appears the ID number is related to the order in which recognizers are installed. I installed German first, English second, Spanish third (for whatever reason).
Here's how the IDs show up:
IDs.PNG
IDs.PNG (4.72 KiB) Viewed 5457 times
Regards,
burque505
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

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

02 Jun 2018, 12:42

Here's what I did to get HotVoice working on my Win7 SP1 64-bit machine:
1) In general, I followed the instructions on this page.
2) First, I downloaded and installed the 64-bit Version 11 Speech Platform runtime from here.
3) Second, I downloaded and installed the 64-bit Version 11 Speech Platform SDK from here.
4) Third, I downloaded and installed several Version 11 languages from here.
I also switched out the included HotVoice.dll for the CultureOptimize.zip version evilC provided above. I'm not sure if this step was required or not, but it certainly did not hurt.
The ID number of the installed language appears to be determined by installation order, and not by the default language of my OS. I installed German first, English second, and Spanish third (although I had intended to install English first, I clicked on the wrong installer). The IDs display as below:
IDs.PNG
IDs.PNG (4.72 KiB) Viewed 5449 times
To my surprise, recognition works in English for the Demo.ahk script using all four of the recognizers shown, including the Microsoft Lightweight Speech Recognizer.

Here is a test script based on Simple Example.ahk, which works for me:

Code: Select all

; Simple German example
; Test of German recognition
; This script demonstrates a single initial word ("Bundesrepublik")

#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()

; Add the word "Test" to it
testGrammar.AppendString("Bundesrepublik")

; Load the Grammar
hv.LoadGrammar(testGrammar, "Bundesrepublik", Func("MyFunc"))

hv.StartRecognizer()

return

MyFunc(grammarName, words){
	ToolTip % "Command: " grammarName " was triggered @ " A_TickCount " with " words.Length() " words"
}
Note the ID in the script needed to match the ID for the recognizer. In the following script it's changed to '2' for Spanish:

Code: Select all

; Test of Spanish recognition
; This script demonstrates a phrase("Me gustaría ir a la playa")

#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(2)

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

; Add the word "Test" to it
testGrammar.AppendString("Me gustaría ir a la playa")

; Load the Grammar
hv.LoadGrammar(testGrammar, "Me gustaría ir a la playa", Func("MyFunc"))

hv.StartRecognizer()

return

MyFunc(grammarName, words){
	ToolTip % "Command: " grammarName " was triggered @ " A_TickCount " with " words.Length() " words"
}
English, German and Spanish all work with the simple examples.

Regards,
burque505
Last edited by burque505 on 02 Jun 2018, 12:57, edited 1 time in total.
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

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

02 Jun 2018, 12:55

Hmm, is Speech Recognition easier to process in German, what with you guys munging words together like that?
Thanks for the list - so it appears that you did not need any of the things outside of stuff that I had linked, but maybe some of the things that I marked as either/or bitness-wise, you actually needed both?
If the CultureOptimize version does not break anything, I think I will commit it then, as it seems a lot more sensible
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

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

02 Jun 2018, 12:59

:) Well, English is my native language, so I'm probably hammering both German and Spanish, but they both work.
In my case, I'm not sure whether some of what I did was optional. But the CultureOptimize version definitely did not break anything for me.

Here's another example in German based on Choices.ahk:

Code: Select all

; This script demonstrates a single initial word ("Testen"), followed by a choice of "rauf", "runter", "links" or "rechts"

#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()

; Add the word "Test" to it
testGrammar.AppendString("Testen")

; Create a new Choices object with four direction choices
directionChoices := hv.NewChoices("rauf, runter, links, rechts")

; Add the direction choices to the Grammar
testGrammar.AppendChoices(directionChoices)

; Load the Grammar
hv.LoadGrammar(testGrammar, "Testen", Func("MyFunc"))

hv.StartRecognizer()

return

MyFunc(grammarName, words){
	ToolTip % "Command: " grammarName " " words[2]
}
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

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

02 Jun 2018, 13:22

Maybe what we should do is instead of use an ID number, use the name of the Culture?

ie, it could maybe be hv.Initialize("DE") or whatever.
I wonder if multiple recognizers can co-exist for different languages?

I suppose I could just add a method to try and find, for example, a german language recognizer and return it's ID.
Then scripts which are inherently german could use this method to get an appropriate ID.
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

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

02 Jun 2018, 13:38

Maybe so, seeing as the ID _seems_ to be based on installation order of languages. To tell you the truth, I haven't tried any of these scripts leaving the ID at 0 to see if they'll work with all languages, but I will, and I'll edit this post.

EDIT: The ID does definitely make a difference for recognition, although some words get recognized regardless of which ID I choose. Matching the ID to the target language is definitely better.
By the way, for the benefit of those just joining us :) here's a script which runs Firefox, Word, Excel or Outlook, depending on whether you say "Run Firefox", "Run Word", "Run Excel" or "Run Outlook".

EDITED EDIT: NOT WORKING in a fashion. I have to say "Run Winword", "Run Excel", "Run Firefox", or "Run Excel", but so far it seems accurate.
Spoiler
Edit: Glitch. TStill tinkering, but this works.

Regards,
burque505
ArchCrunch
Posts: 2
Joined: 05 Jul 2018, 17:35

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

05 Jul 2018, 17:41

Hi,

Is this working on Windows 10? I am not getting any errors, but the demo doesn't seem to respond at all. The only thing is that the volume is moving a bit when sound occurs, but the text box below appears empty.

Any ideas?

Thanks
ArchCrunch
Posts: 2
Joined: 05 Jul 2018, 17:35

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

08 Jul 2018, 08:09

Hi, It worked! I think I was not as loud as I should have been. It is not working 100% of the time though. Is there a way to print what the mic is actually understanding?
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

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

09 Jul 2018, 07:31

It can be debugged via the API, but HotVoice does not display it until it is recognized.
How high is the slider moving when you speak? If it is not getting much volume, it might not be that reliable.
I find that with most mics, I need to crank the input level to full and/or enable "Mic Boost".
atxbilly
Posts: 1
Joined: 12 Jul 2018, 14:09

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

12 Jul 2018, 14:18

I used HotVoice to create a safe word for Path of Exile. Now, when I say, "Bears", it checks to see the game is running and closes it before the bears kill me. I also use it to cast spells hands free. Thanks for the great project!
PGilm
Posts: 4
Joined: 14 Jun 2016, 16:19

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

28 Aug 2018, 17:07

I'm getting the DLLs in the HotVoice Folder are blocked message and have run the powershell command in the lib folder (where the dlls are) and the parent, where Demo.ahk is. Is there a trick for using with Win 8.1 I'm on? I'm more or less following the Win 7 instructions with no luck.
PGilm
Posts: 4
Joined: 14 Jun 2016, 16:19

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

29 Aug 2018, 14:47

Yup, cmd as admin then into ps did it . . . Thx! Great work. I was tapping into the WSR engine for my earlier efforts with less success. Was I using the lightweight recognizer there?

BTW, is there a typo in line 21 of hv.ahk? "nanme" for "name"? Fixing it seems to not break anything. :)
ghostyzx
Posts: 2
Joined: 09 Dec 2018, 16:54

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

09 Dec 2018, 17:15

Awesome library!

I'm trying to find a way to run it nonstop, that means I need to pause the voice recognition from time to time, I need to be able to manually stop&restart the voice recognition (noise in the room, video playing, etc). Right there's only the method StartRecognizer to start things, woudn't be possible to implement also something like StopRecognizer?

Possible workarounds for now are the following:
1) have code in each triggered function that checks if we should be in a "paused" state and ignore the recognitions
2) have the voice recognition code in a separate ahk script and start/stop it on demand
r2997790
Posts: 71
Joined: 02 Feb 2017, 02:46

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

11 Dec 2018, 11:22

I've been meaning to revisit this speech recognition stuff for ages. Wonderful work @evil_c

I was wondering if you, or someone else could help me understand how to adapt the code to do the following...

Activation word / word listened for ("Test", in the demo you included with the script)

... but then... I'd like to feed it a string, rather than a single word, like the up, down, left, right -- in your example.

Something like this....

Simon (activated)

"Open Microsoft Word" < it would capture and interpret a string rather than a single word.

That would open the opportunity for...

Open Word
Open Excel
Close Word
Close Excel

etc. opens up a lot of opprtunities if it can interpret a string of characters.

I tried adding strings to hv.NewChoices but without success.

Does anyone have an idea of how to do it? Thanks!
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

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

11 Dec 2018, 13:22

This library does not support recognition of arbitrary words - you need to give it a list of all possible application names in order to support this.

See how the demo code implements the "call name on their phone" example

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 106 guests