Page 1 of 6

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

Posted: 10 Jul 2017, 17:16
by evilC
This library allows you to use your voice as if it were a hotkey.

The below code makes the word "Test" trigger the function MyFunc()

Code: Select all

; 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("Test")

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

hv.StartRecognizer()

return

MyFunc(grammarName, words){
	ToolTip % "Command: " grammarName " was triggered @ " A_TickCount " with " words.Length() " words"
}
Documentation / Download

Re: [POC] HotVoice - Speech Recognitionn + Volume detection for AHK (C# DLL)

Posted: 15 Jul 2017, 19:07
by Ridwan
Nice..,
Can i use it for dictating?

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

Posted: 16 Jul 2017, 04:46
by evilC
No.
It will only recognize the words that you set as hotkeys.

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

Posted: 21 Jul 2017, 00:15
by scriptor2016
this looks REALLY useful. But it throws me an error message:





Error: 0x80131604 -
Source: mscorlib
Description: Exception has been thrown by the target of an invocation.
HelpFile: (null)
HelpContext: 0

Specifically: CreateInstance

Line#
145: Return,compilerRes[FileName="" ? "CompiledAssembly" : "PathToAssembly"]
146: }
149: {
150: VarSetCapacity(GUID, 16, 0)
151: Return,DllCall("ole32\CLSIDFromString", "wstr", sGUID, "ptr", &GUID) >= 0 ? &GUID : ""
152: }
007: asm := CLR_LoadLibrary("HotVoice.dll")
---> 008: hv := asm.CreateInstance("HotVoice")
010: Gui,Add,Text,Center ww00,Volume
011: Gui,Add,Slider,xm w300 hwndhSlider
012: Gui,Show,,HotVoice
015: hv.SubscribeWord("Fire", Func("Fire"))
016: hv.SubscribeVolume(Func("AxisEvent"))
018: {
019: ToolTip,"Fire @ " A_TickCount

Continue running the script?

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

Posted: 21 Jul 2017, 04:14
by evilC
Yeah, there are a LOT of things which need to be installed for this to work, I need to work out exactly what is required. Will try and take a look at it this weekend

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

Posted: 21 Jul 2017, 08:47
by BGM
This is very interesting to me and I will be keeping a watch on this topic!

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

Posted: 02 Mar 2018, 14:03
by Froggy85
I would also be interested. Please make it as simple as possible.

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

Posted: 24 May 2018, 18:43
by evilC
I did some more work on this tonight, and thanks to Cap'n Odin for helping test

Improved logging and stuff, better demo

It seems that all you need to install is the x86 / x64 (Match to what version of AHK you have installed, or just install both) Runtime
Plus one language pack (eg MSSpeech_SR_en-US_TELE.msi)

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

Posted: 25 May 2018, 14:49
by evilC
HotVoice 0.0.3 has now been released on GitHub: https://github.com/evilC/HotVoice
I started off the documentation, added a basic example, but otherwise it is identical to 0.0.2

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

Posted: 26 May 2018, 02:43
by gregster
Cool. Could be useful. Thanks a lot!

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

Posted: 26 May 2018, 13:20
by evilC
v0.0.4 released with new "Choices" POC
https://github.com/evilC/HotVoice/releases/tag/v0.0.4

Demo: "Choices Example.ahk"

1) Window Manipulation example
Verbs: Launch, Close, Minimize, Maximize, Restore
Choices: Notepad, DosBox
Example: "Launch Notepad".

2) Volume control example
Verbs: Volume
Choices: Any number from 0-100
Example: "Volume 55"

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

Posted: 26 May 2018, 18:55
by SpecialGuest
Thanks for sharing this. Pretty fun to play around with and useful as well.
I did notice that the last version makes two-worded triggers throw an error (due to the choices I guess) :
Is there any way to use both ?
.SubscribeWord with two-worded commands and .SubscribeWordWithChoiceList

Cheers

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

Posted: 26 May 2018, 20:01
by evilC
Been working on a new GrammarVars branch - I am thinking of moving over to this way of doing things.

You can build up grammar like so:

Code: Select all

; -------- Volume Command ------------
hv.GrammarVarAddChoiceVar("percentPhrase", "Percent")
hv.GrammarVarAddString("percentPhrase", "percent")

hv.ChoiceVarAdd("fractionChoices", "quarter, half, three-quarters, full")
hv.GrammarVarAddChoiceVar("fractionPhrase", "fractionChoices")

hv.GrammarVarAddString("volumeCommand", "Volume")
hv.GrammarVarAddGrammarVars("volumeCommand", "fractionPhrase, percentPhrase")

LV_Add(, "Volume", hv.GrammarVarLoad("volumeCommand", Func("Volume")))
LV_ModifyCol(1, 80)

; -------- Call Contact Command -------------
hv.ChoiceVarAdd("females", "Anne, Mary")
hv.GrammarVarAddChoiceVar("callFemales", "females")
hv.GrammarVarAddString("callFemales", "on her")

hv.ChoiceVarAdd("males", "James, Sam")
hv.GrammarVarAddChoiceVar("callMales", "males")
hv.GrammarVarAddString("callMales", "on his")

;// Create a Choices object that contains a set of alternative phone types.
hv.ChoiceVarAdd("phoneTypes", "cell, home, work")


;// Construct the phrase.
hv.GrammarVarAddString("CallGrammar", "Call")
hv.GrammarVarAddGrammarVars("CallGrammar", "callFemales, callMales")
hv.GrammarVarAddChoiceVar("CallGrammar", "phoneTypes")
hv.GrammarVarAddString("CallGrammar", "phone")

LV_Add(, "CallContact", hv.GrammarVarLoad("CallGrammar", Func("CallContact")))
Image

I have not made a release, but I have attached a zip that contains this new version.

Have a play and see what you think.

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

Posted: 26 May 2018, 20:06
by evilC
@SpecialGuest if you put a hyphen between two-words, it seems to count as one ;)
I have learned a ton since I did the first version, what I am working on now does not suffer from the same problem.
The whole project is in a high state of flux at the moment, trying to work out how to provide max flexibility but also not force too much complexity on the user - not sure how long those old methods will last and if it is worth going back and fixing them...

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

Posted: 27 May 2018, 08:00
by SpecialGuest
A hyphen works indeed 8-) Thanks and keep up the good work. It looks promising.
I'll be sure to test that new version too later on as well but first I'm trying a few things with the "old" version.

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

Posted: 27 May 2018, 08:41
by evilC
Tinkering around today, I think I have hit upon a solution which is simpler - that whole "GrammarVar" system just did not quite gel for me.
Unfortunately, COM does not seem to support variable number of parameters in a function call, but I am experimenting with the idea of 10 parameter functions with optional parameters as a work-around.
This allows you to work in AHK with objects, build them up using AHK variables, and then load the finished result into the recognizer.
I am not sure you are gonna be wanting to add more than 10 grammar branches in a node, and we can always maybe add more.
This would not affect Choices - you can add a choice list of arbitrary length.

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

Posted: 27 May 2018, 13:38
by evilC
Version 0.1.0 has now been released.
https://github.com/evilC/HotVoice/releases/tag/v0.1.0
Syntax has completely changed - there are a few more steps involved now for a basic setup, but the power and flexibility of it increased massively.

I hope I struck the right balance.
I could maybe re-add equivalents to the old methods to enable simple one-line additions though

Thoughts?

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

Posted: 27 May 2018, 13:53
by burque505
Hi, I get this error and the PowerShell command doesn't cure it. I tried running it in the script folder and the lib folder.
EDIT: AHK_L 1.1.28.02 U64, Win7 SP1 64-bit
EDIT: I had long ago changed references to "null" in CLR.ahk to "nulo" for the same reason you mention in the script, AHK_H compatibility. I commented out the CLR section in the script and referenced my own lib, but got the same result (which seems only logical).

Code: Select all

---------------------------
Demo.ahk
---------------------------
HotVoice.dll failed to load

Dll may be blocked. Try running the powershell command
Get-ChildItem -Path '.' -Recurse | Unblock-File
in the script folder
---------------------------
OK   
---------------------------

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

Posted: 27 May 2018, 15:18
by evilC
Is this with all version, or just HotVoice 0.1.0?

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

Posted: 27 May 2018, 17:51
by burque505
In 0.0.3 and 0.0.4, the gui displays but HotVoice.dll won't load. In 0.1.0, the gui does not display and HotVoice.dll won't load.