AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Voice Recognition COM
Goto page 1, 2  Next
 
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions
View previous topic :: View next topic  
Author Message
Sean



Joined: 12 Feb 2007
Posts: 1281

PostPosted: Fri Dec 21, 2007 2:44 am    Post subject: Voice Recognition COM Reply with quote

I rewrite the script in the following topic to use COM Standard Library, which is recommended over CoHelper version:
http://www.autohotkey.com/forum/viewtopic.php?t=20493

Code:
#Persistent
OnExit, CleanUp

COM_Init()
plistener:= COM_CreateObject("SAPI.SpSharedRecognizer")
pcontext := COM_Invoke(plistener, "CreateRecoContext")
pgrammar := COM_Invoke(pcontext , "CreateGrammar")
COM_Invoke(pgrammar, "DictationSetState", 0)
prules := COM_Invoke(pgrammar, "Rules")
prulec := COM_Invoke(prules, "Add", "wordsRule", 0x1|0x20)
COM_Invoke(prulec, "Clear")
pstate := COM_Invoke(prulec, "InitialState")

; Add here the words to be recognized!
COM_Invoke(pstate, "AddWordTransition", "+" . 0, "One")
COM_Invoke(pstate, "AddWordTransition", "+" . 0, "Two")
COM_Invoke(pstate, "AddWordTransition", "+" . 0, "Three")
;;

COM_Invoke(prules, "Commit")
COM_Invoke(pgrammar, "CmdSetRuleState", "wordsRule", 1)
COM_Invoke(prules, "Commit")
pevent := COM_ConnectObject(pcontext, "On")
Return

CleanUp:
COM_Release(pevent)
COM_Release(pstate)
COM_Release(prulec)
COM_Release(prules)
COM_Release(pgrammar)
COM_Release(pcontext)
COM_Release(plistener)
COM_Term()
ExitApp

OnRecognition(prms, this)
{
   presult := COM_DispGetParam(prms, 3, 9)
   pphrase := COM_Invoke(presult, "PhraseInfo")
   sText   := COM_Invoke(pphrase, "GetText")
   COM_Release(pphrase)
;   Add custom operations from here!
}
Back to top
View user's profile Send private message
etopsirhc



Joined: 12 Mar 2008
Posts: 9
Location: OR

PostPosted: Wed Mar 12, 2008 9:43 pm    Post subject: Reply with quote

ok i'm haveing a problem with your script and i have no idea how to fix it here's the error

Error: Call to nonexistent function.
specifically:COM_Init()
(points to the line in code)
the program will exit

how can i fix this Question
Back to top
View user's profile Send private message
tic



Joined: 22 Apr 2007
Posts: 1334

PostPosted: Wed Mar 12, 2008 9:49 pm    Post subject: Reply with quote

Quote:
I rewrite the script in the following topic to use COM Standard Library
Question
Back to top
View user's profile Send private message
etopsirhc



Joined: 12 Mar 2008
Posts: 9
Location: OR

PostPosted: Wed Mar 12, 2008 10:24 pm    Post subject: Reply with quote

i have that but it still dosent work
Back to top
View user's profile Send private message
Guest






PostPosted: Fri Mar 14, 2008 7:48 am    Post subject: Reply with quote

Read about Standard Library:
http://www.autohotkey.com/docs/Functions.htm#lib
Back to top
etopsirhc



Joined: 12 Mar 2008
Posts: 9
Location: OR

PostPosted: Fri Mar 14, 2008 11:01 pm    Post subject: Reply with quote

ok i got it to kinda work but now it says

No Event Interface Exists! Now exit the application.

so how do i fix that now
Back to top
View user's profile Send private message
Guest






PostPosted: Sat Mar 15, 2008 12:46 am    Post subject: Reply with quote

Read the original thread linked at the top. You need to install
Speech SDK 5.1
Back to top
DranDane



Joined: 26 Jun 2007
Posts: 54

PostPosted: Mon Mar 17, 2008 5:25 pm    Post subject: Reply with quote

Thank you for this sample. It's good to see it's possible to use ahk with speech recognition.

BUT I'm still thinking that speech recognition should be added in the core C++ code of ahk and be implemented like hotstrings.


Code:

"What time is it"::
  ;gives the time
return
Back to top
View user's profile Send private message
maximina



Joined: 17 Oct 2007
Posts: 10

PostPosted: Mon Mar 17, 2008 10:21 pm    Post subject: Reply with quote

Anonymous wrote:
Read the original thread linked at the top. You need to install
Speech SDK 5.1


Which parts of the SDK are needed?
Back to top
View user's profile Send private message
TodWulff



Joined: 29 Dec 2007
Posts: 99

PostPosted: Sun Mar 30, 2008 7:11 pm    Post subject: Re: Voice Recognition COM Reply with quote

Sean wrote:
I rewrite the script in the following topic to use COM Standard Library, which is recommended over CoHelper version:
http://www.autohotkey.com/forum/viewtopic.php?t=20493
^^^Nice Tool!^^^

Hey Sean.

Thanks for the script. I have been able to get it running and working stand alone reasonably well (I occasionally get the no interface dialog, but I suspect that it is because I am being too impatient (opening a second instance of the script while the first one is releasing it resources, etc.) and confusing the underlying MS framework).

At any rate, I wanted to take a second to ask you if you'd (or someone else who is also knowledgeable) be willing to take a minute and explain the script's functionality a bit (as a teaching/learning exercise, as I am still absorbing the various concepts...). I'd like to evaluate incorporating the speech recognition into my project, but not understanding how it is actually able to do what it is doing causes me some inability to properly evaluate it.

So, I'll pose my questions:

From the manual, I understand the following:

The Manual wrote:
A script that is not persistent and that lacks hotkeys, hotstrings, OnMessage, and GUI will terminate after the auto-execute section has completed. Otherwise, it will stay running in an idle state, responding to events such as hotkeys, hotstrings, GUI events, custom menu items, and timers.


So, with the #persistent after including the COM library, the script executes up to the evaluation/assignment of pevent, and then goes idle after same, waiting for events to occur.

This is what I am struggling with: How the hell is the script triggered to cause the OnRecognition function to kick off? i.e. what faculties of AHK are you employing to cause this functionality to exist. An explanation and/or a link to the manual would be greatly appreciated.

I suspect that it has to do with COM and COMevents, but I am not able to glean how this is actually implemented from your code. I suspect that it is probably a concept that is easily grasped, once 'verbalized'.?.

A 2nd question related to the Speech SDK: I suspect that the speech SDK facilities that are being employed are indeed NOT speaker independent - i.e. that some training would have to have taken place previously, so that the SDK's tool set has a frame of reference for the user. Is this indeed the case, or is it using generic enough speech recognition patterns to allow for user-independent voice recognition?

Thanks so much. Your time, in reviewing my questions, consider same, and replying to advise, is greatly appreciated.

Have a great day.

-t
_________________
When replying, please feel free to address me as Tod or t. My AHK.net site...
Back to top
View user's profile Send private message
BoBoĻ
Guest





PostPosted: Sun Mar 30, 2008 7:21 pm    Post subject: Reply with quote

@ TodWulff
Just to let you know ... don't be angry if a German won't prefer to call you [Tod]
Back to top
TodWulff



Joined: 29 Dec 2007
Posts: 99

PostPosted: Sun Mar 30, 2008 7:24 pm    Post subject: Reply with quote

BoBoĻ wrote:
@ TodWulff
Just to let you know ... don't be angry if a German won't prefer to call you [Tod]

OK, I am obviously a bit ignorant here, admittedly, so please do me the flavor of bringing me up to speed so as to remove any egg that I might have on my face... TIA. Anxiously anticipating an explanation... Smile

[EDIT] Didn't notice the link. Sorry. Yikes. Fully understood. Thanks! [/EDIT]
_________________
When replying, please feel free to address me as Tod or t. My AHK.net site...
Back to top
View user's profile Send private message
Bling170



Joined: 24 Apr 2008
Posts: 1

PostPosted: Thu Apr 24, 2008 6:47 am    Post subject: Reply with quote

Bravo on the conversion. But may I ask, what are some of the optional parameters I can pass in, to tweak and adjust the way things work? Any flexibility here.... does anybody know? Smile
Back to top
View user's profile Send private message
infogulch



Joined: 27 Mar 2008
Posts: 114
Location: KC, MO

PostPosted: Sun Apr 27, 2008 5:06 am    Post subject: Reply with quote

maximina wrote:
Which parts of the SDK are needed?

That download page says this:
Microsoft Website wrote:
Important File Download Details

* If you want to download sample code, documentation, SAPI, and the U.S. English Speech engines for development purposes, download the Speech SDK 5.1 file (SpeechSDK51.exe).

* If you want to use the Japanese and Simplified Chinese engines for development purposes, download the Speech SDK 5.1 Language Pack file (SpeechSDK51LangPack.exe) in addition to the Speech SDK 5.1 file.

* If you want to redistribute the Speech API and/or the Speech engines to integrate and ship as a part of your product (e.g. AHK) **Hint**Hint** Wink, download the Speech 5.1 SDK Redistributables file (SpeechSDK51MSM.exe).

* If you want to get only the Mike and Mary voices redistributable for Windows XP, download Mike and Mary redistributables (Sp5TTIntXP.exe).

* If you only want the documentation, download the Documentation file (sapi.chm).
(2maximina: So you'd probably want to just go with the first one: "SpeechSDK51.exe")

Hey guys, look at that - microsoft's dropping hints for AHK. and wink smileys too, interesting... Very HappyVery Happy **LooksAway&Whistles**
_________________
Back to top
View user's profile Send private message
infogulch



Joined: 27 Mar 2008
Posts: 114
Location: KC, MO

PostPosted: Wed Apr 30, 2008 6:31 am    Post subject: Reply with quote

This is really cool, thnx. Very Happy I'll have to get a headset or something so it can understand me better. Razz

Anyway, I have some questions about this. Any answers greatly appreciated. Smile

1.__________
As with TodWulff, I don't understand how the "OnRecognition()" function is called. I tried looking through the COM lib, but it references itself so much, I had my head spinning by the 3rd func. Razz (bit manipulation is a bit over my head anyway)
It seems to work similar to "OnMessage()", does COM set that up? or is OnRecognition a built-in function by it's own right?
I have a simplified idea of how it works, please correct me if I'm wrong: (probably am, so that means "please correct me", i guess Wink)
Quote:
You pass the word you want to recognize to COM along with some other info, COM tells SDK which word to look for, and dynamically sets up an OnMessage based on that. Then when SDK recognizes a word, it sends a message to the script telling it that the word was recognized, COM receives that message, and sends it to OnRecognition, which uses COM agian to turn it back into the text you get from the var: "sText"
Is that even close? Even if, I still don't understand how OnRecognition is defined as the function to go to if it finds it, unless that's just part of COM.

2.__________
How would I clear words from being recognized anymore? Can I do it individually or does it have to be done all at once? If all at once, is it "COM_Release(pstate)"? (Because you use "pstate" in the COM_Invoke for recognizing a word, and that's in the OnExit subroutine)

3.__________
Is there a way to tell it to receive All words SDK recognizes? I know it would be unreliable, so I would only use it momentarily, but I would like to know. (does it have to do with the "+" . 0 paramater passed to the COM_Invoke?)

Thanks agian for any help. Very Happy Voice recognition is really cool, and I would love to understand it more so I can meet it's potential better. Cool
_________________
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    AutoHotkey Community Forum Index -> Scripts & Functions All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group