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

Post your working scripts, libraries and tools for AHK v1.1 and older
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

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

10 Jul 2017, 17:16

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
Last edited by evilC on 27 May 2018, 13:35, edited 6 times in total.
Ridwan
Posts: 144
Joined: 17 Oct 2015, 21:06
Location: Indonesia

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

15 Jul 2017, 19:07

Nice..,
Can i use it for dictating?
scriptor2016
Posts: 844
Joined: 21 Dec 2015, 02:34

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

21 Jul 2017, 00:15

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?
Froggy85
Posts: 1
Joined: 31 Mar 2017, 15:45

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

02 Mar 2018, 14:03

I would also be interested. Please make it as simple as possible.
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

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

24 May 2018, 18:43

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)
Attachments
Source 0.0.2.zip
(1.43 MiB) Downloaded 216 times
Demo 0.0.2.zip
(231.7 KiB) Downloaded 198 times
gregster
Posts: 8916
Joined: 30 Sep 2013, 06:48

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

26 May 2018, 02:43

Cool. Could be useful. Thanks a lot!
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

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

26 May 2018, 13:20

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"
SpecialGuest
Posts: 26
Joined: 15 May 2016, 07:49

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

26 May 2018, 18:55

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

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

26 May 2018, 20:01

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.
Attachments
HotVoice.zip
GrammarVars POC
(233.2 KiB) Downloaded 155 times
Last edited by evilC on 26 May 2018, 20:08, 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)

26 May 2018, 20:06

@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...
SpecialGuest
Posts: 26
Joined: 15 May 2016, 07:49

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

27 May 2018, 08:00

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.
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

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

27 May 2018, 08:41

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.
User avatar
evilC
Posts: 4822
Joined: 27 Feb 2014, 12:30

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

27 May 2018, 13:38

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?
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

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

27 May 2018, 13:53

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   
---------------------------
burque505
Posts: 1731
Joined: 22 Jan 2017, 19:37

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

27 May 2018, 17:51

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.

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 115 guests