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

Post your working scripts, libraries and tools for AHK v1.1 and older
Daws
Posts: 1
Joined: 19 Apr 2020, 05:38

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

Post by Daws » 19 Apr 2020, 05:48

For the ones who have the error:

HotVoice.dll failed to load
Dll may be blocked. Try running the powershell command Get-ChildItem -Path '.'-Recurse Unblock-File in the script folder


Be sure to have the Microsoft Speech platform Runtime Server installed:
https://www.microsoft.com/en-us/download/details.aspx?id=27225
And chose one or more languages pack:
https://www.microsoft.com/en-us/download/details.aspx?id=27224

I got this error too, and found that I need the runtime server.
Moreover be sure to use the AutoHotkey Unicode 64Bit.

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

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

Post by scriptor2016 » 25 Apr 2020, 00:00

Dang. Still won't work :(

User avatar
submeg
Posts: 326
Joined: 14 Apr 2017, 20:39
Contact:

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

Post by submeg » 01 May 2020, 06:30

Hey @evilC, this is amazing!

I went through this thread, and in this post, you add the prefix "Open" to the app name.

I would like to build on that, so that it actually opens the app. I tried to use the Switch command to recognise the word that is chosen, and then open the corresponding app. My script is as per below:

Code: Select all


MyFunc(grammarName, words){
	
    ToolTip % "Command: " grammarName " " words[2]
	msgbox % words[2]
	
	Switch % words[2]
	{
	Case Word:
		msgbox WORD
		run WINWORD.exe /w
		
	Case Excel:
		run, excel.exe /x
		
	Case PowerPoint:							;to do more than one case at a time use Case 2, 3:
		run,Powerpnt.exe /x
		
	Case Outlook:
		Run, Outlook.exe
		
		
	}

}

Trying to work out what to use as the choice for Switch; is it even possible?
____________________________________
Check out my site, submeg.com
Connect with me on LinkedIn
Courses on AutoHotkey :ugeek:


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

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

Post by scriptor2016 » 18 Jul 2020, 13:20

Just wondering, can anyone confirm that this script works on Windows7 ?

I've still had no luck but am very hopeful that there is a way to get it running on my Win7 computer :/

burque505
Posts: 1734
Joined: 22 Jan 2017, 19:37

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

Post by burque505 » 18 Jul 2020, 17:40

@scriptor2016, v1.4 is working on my Win7 SP1 64-bit system. Downloaded from here. German and Spanish work too, by the way. :D

If you just clone the github repo and run an example, for sure it won't work. You need the zip file from the releases page. There are other requirements too, listed on this github page.

Regards,
burque505

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

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

Post by scriptor2016 » 19 Jul 2020, 14:12

burque505 wrote:
18 Jul 2020, 17:40
@scriptor2016, v1.4 is working on my Win7 SP1 64-bit system. Downloaded from here. German and Spanish work too, by the way. :D

If you just clone the github repo and run an example, for sure it won't work. You need the zip file from the releases page. There are other requirements too, listed on this github page.

Regards,
burque505
hi burque505


I followed all the instructions and am still getting this message:

HotVoice.dll failed to load
Dll may be blocked. Try running the powershell command Get-ChildItem - Path '.' - Recurse Unblock-File in the script folder

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

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

Post by scriptor2016 » 19 Jul 2020, 14:14

The instructions were easy to follow, but there was one problem.

I cannot run "unblock.ps1" as administrator, because "run as administrator" is not appearing when I right-click the file. So instead, I clicked on "Run With Powershell".

Could this be a problem?

(By the way, I do not have the file "unblock1.ps1", but instead the file is called "Unblocker.ps1")

burque505
Posts: 1734
Joined: 22 Jan 2017, 19:37

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

Post by burque505 » 19 Jul 2020, 14:52

Gosh, I don't know if that'll be a problem or not. Are you able to run PowerShell as admin? If so, open Powershell, navigate to the directory with 'Unblocker.ps1' and run it from there with PowerShell.
Capture.PNG
Capture.PNG (18.42 KiB) Viewed 7551 times

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

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

Post by scriptor2016 » 19 Jul 2020, 15:26

ok, so I managed to get into powershell to run the Unblock.ps1 script.

But it gave me the following error:

\Unblocker1.ps1 cannot be loaded because the execution of scripts is disabled on this system. Please see "get-help about_signing" for more details.

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

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

Post by scriptor2016 » 19 Jul 2020, 15:54

I managed to set powershell to unrestricted, so the above error message has been taken care of.


After navigating to the proper directory, tried all of these:

./Unblocker.ps1
./Unblocker
. ./Unblocker.ps1
. ./Unblocker
.\Unblocker.ps1
.\Unblocker
. .\Unblocker.ps1
. .\Unblocker

But I get this error:
"The term 'Unblock-File' is not recognized as the name of a cmdlet, function, script file, or operable program...etc." error.

Anyhoo. Looks like this is a lost cause. If I simply right-click the Unblocker.ps1 file in windows explorer, then choose "Run With Powershell" , a small black pop-up window appears for less than a second then disappears. I'm guessing that window is a .cmd command prompt window or something - but it doesn't look like the PowerShell window.

I've been at this for many months now and have never solved it. Thanks again though, maybe someone else might be able to chime in and see why HotVoice won't run on this system.

Windows7 64-Bit Service Pack 1
Microsoft Speech Platform Runtime is installed as well as the english pack.

burque505
Posts: 1734
Joined: 22 Jan 2017, 19:37

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

Post by burque505 » 19 Jul 2020, 17:24

What version of PowerShell are you running?

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

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

Post by scriptor2016 » 19 Jul 2020, 20:49

hey, thanks for keeping up with this.

I typed in (Get-Host).Version and it returned these results:

Major = 2
Minor = 0
Build = -1
Revision = -1



Also, the target location of my powershell is
%SystemRoot%\system32\WindowsPowerShell\v1.0\powershell.exe

burque505
Posts: 1734
Joined: 22 Jan 2017, 19:37

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

Post by burque505 » 20 Jul 2020, 08:08

Try this, the version is the second result:
version.PNG
version.PNG (28.92 KiB) Viewed 4820 times

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

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

Post by evilC » 20 Jul 2020, 11:35

There's only one command in the unblocker ps1 script - just make sure you have an admin powershell prompt active, copy the one line of code from the ps1 file, then paste it into an admin powershell prompt and run it
The alternative to even needing the blocker is to unblock the files whilst they are still in the zip - you can right-click the HotVoice zip, select properties, then check the unblock box there
Then, when you unzip the files from the hotvoice zip, they are already unblocked

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

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

Post by scriptor2016 » 20 Jul 2020, 12:42

burque505 wrote:
20 Jul 2020, 08:08
Try this, the version is the second result:
version.PNG
Ok, it worked - I've got version 2.0

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

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

Post by scriptor2016 » 20 Jul 2020, 12:47

evilC wrote:
20 Jul 2020, 11:35
There's only one command in the unblocker ps1 script - just make sure you have an admin powershell prompt active, copy the one line of code from the ps1 file, then paste it into an admin powershell prompt and run it
The alternative to even needing the blocker is to unblock the files whilst they are still in the zip - you can right-click the HotVoice zip, select properties, then check the unblock box there
Then, when you unzip the files from the hotvoice zip, they are already unblocked
thanks - I managed to select 'unblock' before unzipping the files, but unfortunately the same "dll may be blocked" error continues to show.

The only other issue was when I ran the 'Demo.ahk' file for the first time, it wouldn't load because it couldn't find the path to the Lib folder in order to include HotVoice.ahk , so I had to change the #Include line at the top of the Demo.ahk

originally, the line looked like something like this:
#include Lib\HotVoice.ahk

but it was directing to some random folder in my hard drive, so i had to change it so it now reads like this:

#include D:\MyScriptFolders\HotVoice\Lib\HotVoice.ahk


..I don't know if this may have caused any issues.

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

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

Post by evilC » 20 Jul 2020, 13:44

If you unzip the zip,all the files should be in the right place and the demo scripts should work.
Are you sure you are downloading a release, or are you maybe using the green "clone or download" button on the main page.
Do you have the DLLs in your zip?

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

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

Post by scriptor2016 » 21 Jul 2020, 00:36

I'm pretty sure I've figured out the #include Lib\HotVoice.ahk issues because I am no longer seeing the error which states it cannot find the HotVoice.ahk in the Lib folder, but the "HotVoice.dll failed to load" error still happens when I run Demo.ahk

But-

If I compile Demo.ahk and then run the .exe, I get this error:

Unable to find lib\HotVoice.dll, exiting...



This is the location of my AHK Lib folder:
C:\Documents and Settings\MyUser\Documents\AutoHotkey\Lib

and inside this Lib folder are:
-HotVoice.ahk
-HotVoice.dll
-Microsoft.Speech.dll



And this is where I downloaded and saved the HotVoice.zip file:
D:\AutoHotKey\Scripts\HotVoice

and in this folder are:
-CHANGELOG.md
-Choices Example.ahk
-Demo.ahk
-HotVoice.zip
-LICENSE
-README.md
-Simple Example.ahk
-Unblocker.ps1
-Lib(the Folder) - is this the Lib folder the script points to, or is it pointing to the C:\Documents and Settings\MyUser\Documents\AutoHotkey\Lib folder?
anyhow, inside this Lib folder are again these 3 files:
---HotVoice.ahk
---HotVoice.dll
---Microsoft.Speech.dll




And, here's the full Demo.ahk code I'm using:

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, Available Recognizers
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, Load selected recognizer`n(Languages supported by this demo: en, fr)
Gui, Add, Text, xm w600 Center, Available Commands
Gui, Add, ListView, xm w600 r10 hwndhAvailableCommands, Name|Grammar
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
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()

if (recognizer.TwoLetterISOLanguageName == "en"){
	; ==== ENGLISH ====
	hv.Initialize(recognizer.Id)
	; -------- Volume Command ------------
	volumeGrammar := hv.NewGrammar()
	volumeGrammar.AppendString("Volume")

	percentPhrase := hv.NewGrammar()
	percentChoices := hv.GetChoices("Percent")
	percentPhrase.AppendChoices(percentChoices)
	percentPhrase.AppendString("percent")

	fractionPhrase := hv.NewGrammar()
	fractionChoices := hv.NewChoices("quarter, half, three-quarters, full")
	fractionPhrase.AppendChoices(fractionChoices)

	volumeGrammar.AppendGrammars(fractionPhrase, percentPhrase)
	hv.LoadGrammar(volumeGrammar, "Volume", Func("LogWords"))
	; Use custom text in listview, else it is too long
	LV_Add(, "Volume", "Volume [[quarter,half,three-quarters,full],[<Number> percent]]")

	; -------- Call Contact Command -------------
	contactGrammar := hv.NewGrammar()
	contactGrammar.AppendString("Call")

	femaleGrammar := hv.NewGrammar()
	femaleChoices := hv.NewChoices("Anne, Mary")
	femaleGrammar.AppendChoices(femaleChoices)
	femaleGrammar.AppendString("on-her")

	maleGrammar := hv.NewGrammar()
	maleChoices := hv.NewChoices("James, Sam")
	maleGrammar.AppendChoices(maleChoices)
	maleGrammar.AppendString("on-his")

	contactGrammar.AppendGrammars(maleGrammar, femaleGrammar)

	phoneChoices := hv.NewChoices("cell, home, work")
	contactGrammar.AppendChoices(phoneChoices)
	contactGrammar.AppendString("phone")

	LV_Add(, "CallContact", hv.LoadGrammar(contactGrammar, "CallContact", Func("LogWords")))
} else if (recognizer.TwoLetterISOLanguageName == "fr"){
	; ==== FRENCH ====
	hv.Initialize(recognizer.Id)
	
	; -------- Volume Command ------------
	volumeGrammar := hv.NewGrammar()
	volumeGrammar.AppendString("Volume")

	percentPhrase := hv.NewGrammar()
	percentChoices := hv.GetChoices("Percent")
	percentPhrase.AppendChoices(percentChoices)
	percentPhrase.AppendString("Pour-cent")

	volumeGrammar.AppendGrammars(percentPhrase)
	hv.LoadGrammar(volumeGrammar, "FrenchVolume", Func("LogWords"))
	LV_Add(, "Volume", "Volume [<Nombre>] pour cent")
	
	; -------- French Greeting Command ------------
	contactGrammar := hv.NewGrammar()
	contactGrammar.AppendString("Bonjour")

	maleGrammar := hv.NewGrammar()
	maleChoices := hv.NewChoices("Claude, Jaques")
	maleGrammar.AppendChoices(maleChoices)

	contactGrammar.AppendGrammars(maleGrammar)

	LV_Add(, "Greeting (French)", hv.LoadGrammar(contactGrammar, "FrenchGreeting", 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 "`n"
	GuiControl, , % houtput, % t
	; Scroll box to end
	PostMessage, WM_VSCROLL, SB_BOTTOM, 0, Edit1, ahk_id %hGui%
}

^Esc::
GuiClose:
	ExitApp
so, even though it gives the "HotVoice.dll failed to load" error, it is still locating the HotVoice.dll file ... but when compiling Demo.ahk and then running it as Demo.exe, the error says that it cannot find the .dll file.

...what in the world could be wrong here. I'd give anything to get this thing running.

gatifun
Posts: 1
Joined: 04 Aug 2020, 12:02

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

Post by gatifun » 04 Aug 2020, 12:08

Hello! Thanks for your app, it works fine , but maybe you can help me with some functions that I'm struggling but can't make work, thanks in advance

I would like say "7" and the mouse click on a place on window, say "8" and click on other. I've managed to set the "7" but dunno how to add more orders. Could you help me?

Code: Select all

; This script demonstrates a single initial word ("Test")

#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 Seven to it
testGrammar.AppendString("Seven")

; Load the Grammar
hv.LoadGrammar(testGrammar, "Seven", Func("myfunction"))


hv.StartRecognizer()

return

myfunction(grammarName, words){
	WinActivate, game
WinGetPos, winX, winY, winWidth, winHeight, A
X := winWidth * 0.36
Y := winHeight * 0.86
Click %X% %Y%
Click 600, -2600
}

Post Reply

Return to “Scripts and Functions (v1)”