AutoHotkey Community

It is currently May 25th, 2012, 2:20 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 46 posts ]  Go to page 1, 2, 3, 4  Next
Author Message
 Post subject: Voice recognition
PostPosted: June 26th, 2007, 11:18 am 
Offline

Joined: June 26th, 2007, 10:52 am
Posts: 53
Your software is able to recognize a key pressure, a key sequence or a movement of the mouse. It could be nice to be able to bind action to voice orders.

"write a note"::Run notepad

or
^!"write a note"::Run notepad

Other software are already able to recognize the voice but they don't offer all the functions you able to do.

I also invite you to investigate about the GlovePIE software. GlovePIE manage more input devices like speech, joystick, joypad, wiimote, remote devices, etc... but don't offer so much output actions than you are able to do. May I hope a collaboration between those two projects is possible ?


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 26th, 2007, 1:24 pm 
Offline

Joined: April 19th, 2006, 1:02 pm
Posts: 386
Speech Recognition may be possible with COM.
I found an example of how its done in Python.
Code:
from win32com.client import constants
import win32com.client
import pythoncom

"""Sample code for using the Microsoft Speech SDK 5.1 via COM in Python.
    Requires that the SDK be installed; it's a free download from
            http://microsoft.com/speech
    and that MakePy has been used on it (in PythonWin,
    select Tools | COM MakePy Utility | Microsoft Speech Object Library 5.1).

    After running this, then saying "One", "Two", "Three" or "Four" should
    display "You said One" etc on the console. The recognition can be a bit
    shaky at first until you've trained it (via the Speech entry in the Windows
    Control Panel."""
class SpeechRecognition:
    """ Initialize the speech recognition with the passed in list of words """
    def __init__(self, wordsToAdd):
        # For text-to-speech
        self.speaker = win32com.client.Dispatch("SAPI.SpVoice")
        # For speech recognition - first create a listener
        self.listener = win32com.client.Dispatch("SAPI.SpSharedRecognizer")
        # Then a recognition context
        self.context = self.listener.CreateRecoContext()
        # which has an associated grammar
        self.grammar = self.context.CreateGrammar()
        # Do not allow free word recognition - only command and control
        # recognizing the words in the grammar only
        self.grammar.DictationSetState(0)
        # Create a new rule for the grammar, that is top level (so it begins
        # a recognition) and dynamic (ie we can change it at runtime)
        self.wordsRule = self.grammar.Rules.Add("wordsRule",
                        constants.SRATopLevel + constants.SRADynamic, 0)
        # Clear the rule (not necessary first time, but if we're changing it
        # dynamically then it's useful)
        self.wordsRule.Clear()
        # And go through the list of words, adding each to the rule
        [ self.wordsRule.InitialState.AddWordTransition(None, word) for word in wordsToAdd ]
        # Set the wordsRule to be active
        self.grammar.Rules.Commit()
        self.grammar.CmdSetRuleState("wordsRule", 1)
        # Commit the changes to the grammar
        self.grammar.Rules.Commit()
        # And add an event handler that's called back when recognition occurs
        self.eventHandler = ContextEvents(self.context)
        # Announce we've started using speech synthesis
        self.say("Started successfully")
    """Speak a word or phrase"""
    def say(self, phrase):
        self.speaker.Speak(phrase)


"""The callback class that handles the events raised by the speech object.
    See "Automation | SpSharedRecoContext (Events)" in the MS Speech SDK
    online help for documentation of the other events supported. """
class ContextEvents(win32com.client.getevents("SAPI.SpSharedRecoContext")):
    """Called when a word/phrase is successfully recognized  -
        ie it is found in a currently open grammar with a sufficiently high
        confidence"""
    def OnRecognition(self, StreamNumber, StreamPosition, RecognitionType, Result):
        newResult = win32com.client.Dispatch(Result)
        print "You said: ",newResult.PhraseInfo.GetText()
   
if __name__=='__main__':
    wordsToAdd = [ "One", "Two", "Three", "Four" , "boom"]
    speechReco = SpeechRecognition(wordsToAdd)
    while 1:
        pythoncom.PumpWaitingMessages()


I didn't have the time to investigate how to translate it to ahk (if possible at all). Maybe someone else that has a good understanding of COM knows a little Python and has time can investigate this can make it work. Because i am busy with exploring WinSock2 with ahk at the moment. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 27th, 2007, 11:53 am 
Offline

Joined: March 2nd, 2004, 3:36 pm
Posts: 10720
Although it's outside my experience, I would like to extend AutoHotkey's input capabilities to include more types of remote controls, etc. Also, the ability to simulate joystick input (e.g. pressing of buttons) would be great because it would allow a keyboard or mouse to be used as a complete or partial substitute for a joystick.

Thanks for the suggestion.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 28th, 2007, 2:27 pm 
Offline

Joined: April 19th, 2006, 1:02 pm
Posts: 386
I should be able to put out a script within the next week. So keep an eye on this topic and the scripts and functions forum.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: June 28th, 2007, 7:39 pm 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
foom wrote:
I should be able to put out a script within the next week. So keep an eye on this topic and the scripts and functions forum.

I'm all excited !!!

Can't wait !

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 4th, 2007, 6:14 pm 
Offline

Joined: April 19th, 2006, 1:02 pm
Posts: 386
OK i wanted to let you know that i got it working, since ehhrrm, a couple of days now but had no time to clean up the mess so you will need to wait a couple more days. :)


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2007, 4:49 pm 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
Thanks for the update...
Still super-excited to see this!
:P

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: July 5th, 2007, 10:46 pm 
SoggyDog wrote:
Thanks for the update...
Still super-excited to see this!
:P


As am I, looking forward to your follow up post foom!


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 25th, 2007, 1:09 am 
Just a note: Vista comes with built-in voice recognition. Works quite good 8)


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: July 26th, 2007, 6:18 pm 
Offline

Joined: May 2nd, 2006, 11:16 pm
Posts: 800
Location: Greeley, CO
How's it comin'?

I REALLY wanna play with this!

:idea: :!: :D :!: :idea:

_________________
Image
SoggyDog
Dwarf Fortress:
"The most intriguing game I've ever played."


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 9th, 2007, 11:20 am 
Offline

Joined: July 30th, 2007, 8:47 pm
Posts: 21
can't wait..


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 9th, 2007, 3:37 pm 
Offline

Joined: June 26th, 2007, 10:52 am
Posts: 53
Andreas wrote:
Just a note: Vista comes with built-in voice recognition. Works quite good 8)


And the voice recognition is easy to install on XP :wink:

More info here http://clans.gameclubcentral.com/shoot/downloads.php It's a website of shoot 1.6.4 a voice recognition software I don't use any more. The software is good but very limited.

I invite again you to investigate about the GlovePIE software. See my first message.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 10th, 2007, 6:14 am 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
Looks like foom is busy.
Anyway, here is the verbatim translation of the script foom linked.
I can't test it myself as no mike is installed on my machine.
If you hear "Starting Succeeded", then, try to say one/two/three.

NEED CoHelper.ahk.

Code:
#Persistent
OnExit, CleanUp

CoInitialize()
pspeaker := ActiveXObject("SAPI.SpVoice")
plistener:= ActiveXObject("SAPI.SpSharedRecognizer")
pcontext := Invoke(plistener, "CreateRecoContext")
pgrammar := Invoke(pcontext, "CreateGrammar")
Invoke(pgrammar, "DictationSetState", 0)
prules := Invoke(pgrammar, "Rules")
prulec := Invoke(prules, "Add", "wordsRule", 0x1|0x20)
Invoke(prulec, "Clear")
pstate := Invoke(prulec, "InitialState")

; Add here the words to be recognized! Looks like it understands the null pointer.
Invoke(pstate, "AddWordTransition", "+" . 0, "One")
Invoke(pstate, "AddWordTransition", "+" . 0, "Two")
Invoke(pstate, "AddWordTransition", "+" . 0, "Three")
;;

Invoke(prules, "Commit")
Invoke(pgrammar, "CmdSetRuleState", "wordsRule", 1)
Invoke(prules, "Commit")
ConnectObject(pcontext, "On")

If (pspeaker && plistener && pcontext && pgrammar && prules && prulec && pstate)
   Invoke(pspeaker, "Speak", "Starting Succeeded")
Else   Invoke(pspeaker, "Speak", "Starting Failed")
Return

CleanUp:
Release(pstate)
Release(prulec)
Release(prules)
Release(pgrammar)
Release(pcontext)
Release(plistener)
Release(pspeaker)
CoUninitialize()
ExitApp


OnRecognition(prms, this)
{
   Global   pspeaker
   presult := DispGetParam(prms, 3, 9)
   pphrase := Invoke(presult, "PhraseInfo")
   Invoke(pspeaker, "Speak", "You said " . Invoke(pphrase, "GetText"))
   Release(pphrase)
}

#Include CoHelper.ahk


Last edited by Sean on October 22nd, 2007, 8:11 am, edited 6 times in total.

Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 11th, 2007, 1:30 pm 
Offline

Joined: June 26th, 2007, 10:52 am
Posts: 53
Sean,

The script start and I hear "Starting Suceeded". When I say "One" I hear "You said one" and a one second later I get an error message. The script crash and close.

But the most important... the voice recognition works :-D. Thank you.

eventvwr message :

Code:
Event Type:   Error
Event Source:   Application Error
Event Category:   None
Event ID:   1000
Date:      11/08/2007
Time:      14:21:46
User:      N/A
Computer:   WS-P5GL-MX-300
Description:
Faulting application autohotkey.exe, version 1.0.47.3, faulting module sapi.dll, version 5.1.4111.0, fault address 0x0000c969.

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.
Data:
0000: 41 70 70 6c 69 63 61 74   Applicat
0008: 69 6f 6e 20 46 61 69 6c   ion Fail
0010: 75 72 65 20 20 61 75 74   ure  aut
0018: 6f 68 6f 74 6b 65 79 2e   ohotkey.
0020: 65 78 65 20 31 2e 30 2e   exe 1.0.
0028: 34 37 2e 33 20 69 6e 20   47.3 in
0030: 73 61 70 69 2e 64 6c 6c   sapi.dll
0038: 20 35 2e 31 2e 34 31 31    5.1.411
0040: 31 2e 30 20 61 74 20 6f   1.0 at o
0048: 66 66 73 65 74 20 30 30   ffset 00
0050: 30 30 63 39 36 39 0d 0a   00c969..
:lol:


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 11th, 2007, 3:01 pm 
Offline

Joined: February 12th, 2007, 7:54 am
Posts: 2462
DranDuncanDane wrote:
The script start and I hear "Starting Suceeded". When I say "One" I hear "You said one" and a one second later I get an error message. The script crash and close.

I always felt helpless when facing a situation like this where I can't test myself...
BTW, the address in the eventvwr you posted appeared somewhat odd to me.
Anyway, the one I could think of atm that can go wrong is in the following function Rec_Recognition, so I updated it.

Please recopy and try it again, and inform me about the result.


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 46 posts ]  Go to page 1, 2, 3, 4  Next

All times are UTC [ DST ]


Who is online

Users browsing this forum: Bon, MSN [Bot] and 14 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group