| | |
Python for Laptop Robot Speech recognition and TTS.
![]() |
•
•
Join Date: Aug 2007
Posts: 59
Reputation:
Solved Threads: 0
Hello Everyone. I'm new to python and so far, I simply love it! I'm still just starting to get the knack though and there's a lot more I want to know. I've decided to use it mainly for my robots' programming scripts. Right now I'm currently stuck on a simple script on getting my windows vista machine to recognize phrases I say, and reply to them using TTS. It's a learning process in itself.
Bare with me, most of the time I feel like I haven't got a clue when I'm writing a python script. It's the first programming language I'm learning.
Here's the script I'm using on my computer. I'll implement it into my robot later, once I get it to work. I modified it from two python sample scripts by Inigo Surguy and Peter Parente, so a lot of credit goes to them, at least until I become savy enough to write my original speech Recognition and TTS scripts... What I want it to do is wait for me to say "Hello, Aelita" which is what I call my laptop, and respond by addressing my name and asking how I am doing. I'm also trying to get it to tell me the time, whenever I say "Time." It is as follows:
It's working mostly, in that it opens up Microsoft Speech Recognition and recognizes the words I say, and as far as I know the script is free from syntax errors and exceptions. The problem I'm having now is getting the computer's voice to say something back. As of now, the phrase just shows up in the MSR window but doesn't say anything back. I think it has to do with the "speechReco" I write for when the computer's supposed to catch a certain phrase. I don't think its the right term. So, the MSR is recognizing my words, but the python script doesn't, hence no TTS response. I'd appreciate it if maybe someone could help me out with this script, and/or tell me if there's some sort of python syntax dictionary or glossary out there, that tells all the different words you can right in a python script, when to use them, and what they do?
Once again, bare with me. I'm trying to learn as much as I can about this stuff. Thanks.
Bare with me, most of the time I feel like I haven't got a clue when I'm writing a python script. It's the first programming language I'm learning.
Here's the script I'm using on my computer. I'll implement it into my robot later, once I get it to work. I modified it from two python sample scripts by Inigo Surguy and Peter Parente, so a lot of credit goes to them, at least until I become savy enough to write my original speech Recognition and TTS scripts... What I want it to do is wait for me to say "Hello, Aelita" which is what I call my laptop, and respond by addressing my name and asking how I am doing. I'm also trying to get it to tell me the time, whenever I say "Time." It is as follows:
Python Syntax (Toggle Plain Text)
#Test Script for computer virtual personality. #Credits to Inigo Surguy (inigosurguy@hotmail.com) and Peter Parente for original #Speech Recognition and TTS scripts. #Further commentary by Surguy from win32com.client import constants import win32com.client import pythoncom import pyTTS impor time tts = pyTTS.Create() tts.Rate = 1 tts.Volume = 90 tts.GetVoiceNames() tts.SetVoiceByName('MS-Anna-1033-20-DSK') """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://www.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 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) if __name__=='__main__': wordsToAdd = [ "Hello Aelita", "Fine", "How are you?", "Not well", "Awful", "Bad", "Not good", "Not too well", "Thank you", "Thanks", "Time" ] speechReco = SpeechRecognition(wordsToAdd) while 1: pythoncom.PumpWaitingMessages() if speechReco("Hello Aelita"): greeting1 = "Hello, Lore-enn. How are you today?" tts.Speak(greeting1) if speechReco("Fine"): great = "Great!" tts.Speak(great) offr1 = "Is there anything I can do for you?" tts.Speak(offr1) if speechReco("Not well") or ("Awful") or ("Bad") or ("Not Good") or ("Not too well"): sorry1 = "That's too bad" sorry2 = "I'm so sorry." tts.Speak(sorry1) or (sorry2) onDuty1 = "If there's anything or need, just let me know." tts.Speak(onDuty1) if speechReco("Thanks") or ("Thank you"): hum1 = "Don't mention it" hum2 = "No problem" hum3 = "Your welcome" tts.Speak(hum1) or (hum2) or (hum3) if speechReco("Time"): timeStr1 = "The time is " + time.asctime(), timeStr2 = "It's " + time.asctime() timeStr3 = "Right now, it's " + time.asctime() tts.Speak(timeStr1) or (timeStr2) or (timeStr3)
It's working mostly, in that it opens up Microsoft Speech Recognition and recognizes the words I say, and as far as I know the script is free from syntax errors and exceptions. The problem I'm having now is getting the computer's voice to say something back. As of now, the phrase just shows up in the MSR window but doesn't say anything back. I think it has to do with the "speechReco" I write for when the computer's supposed to catch a certain phrase. I don't think its the right term. So, the MSR is recognizing my words, but the python script doesn't, hence no TTS response. I'd appreciate it if maybe someone could help me out with this script, and/or tell me if there's some sort of python syntax dictionary or glossary out there, that tells all the different words you can right in a python script, when to use them, and what they do?
Once again, bare with me. I'm trying to learn as much as I can about this stuff. Thanks.
•
•
Join Date: Jul 2006
Posts: 608
Reputation:
Solved Threads: 150
It's good code, seagull (or should I say "Lore-enn"?). You're asking a question that has more to do with the speech recognition module than Python, so I can't directly help. But when I'm stuck on such, I usually try out the help files.
In this case, it looks as if tts.Speak() isn't working like you'd want. So from the command line:
and see if you get anything useful.
BTW, there is a typo in the line "impor time" --> should be "import time". I don't think that'll fix the code, though.
Hope it helps,
Jeff
In this case, it looks as if tts.Speak() isn't working like you'd want. So from the command line:
Python Syntax (Toggle Plain Text)
import pyTTS tts = pyTTS.Create() help(tts.Speak)
and see if you get anything useful.
BTW, there is a typo in the line "impor time" --> should be "import time". I don't think that'll fix the code, though.
Hope it helps,
Jeff
•
•
Join Date: Aug 2007
Posts: 59
Reputation:
Solved Threads: 0
Thanks for the input, jrcagle. Name's actually Loren, but wanted the TTS to pronounce it right.
The script still doesn't seem to be working. I'm not sure its the pyTTS that's not working but it always working fine in the interactive window...But even surguy's original speech recognition script didn't work completely when I downloaded it directly and tried it. The Microsoft Speech Recognition for Vista window still opened up and recognized the phrases I said, but I got no response. In surguy's script, the computer was supposed to print on the screen "You said ", and it would be "One," "Two," "Three," or "Four," depending on which of the four numbers you said. But all that came up in my Microsoft Speech Recognition was "One" "Two" "Three" or "Four." and it does that anyway, even without the python script. No window came up or anything that said, "You said one," or "You said two." I wonder if it has anything to do with Microsoft Speech Recognition which opens every time I run the script. Maybe its interferring somehow, because I don't think Surguy intended his script to work with Microsoft Speech Recognition on a windows Vista machine...
Does anyone know what would happen if I tried it on a different O.S. What if I ran the script in a windows XP or 98 on Microsoft Virtual PC? I think that's what I'll try and see what happens...
The script still doesn't seem to be working. I'm not sure its the pyTTS that's not working but it always working fine in the interactive window...But even surguy's original speech recognition script didn't work completely when I downloaded it directly and tried it. The Microsoft Speech Recognition for Vista window still opened up and recognized the phrases I said, but I got no response. In surguy's script, the computer was supposed to print on the screen "You said ", and it would be "One," "Two," "Three," or "Four," depending on which of the four numbers you said. But all that came up in my Microsoft Speech Recognition was "One" "Two" "Three" or "Four." and it does that anyway, even without the python script. No window came up or anything that said, "You said one," or "You said two." I wonder if it has anything to do with Microsoft Speech Recognition which opens every time I run the script. Maybe its interferring somehow, because I don't think Surguy intended his script to work with Microsoft Speech Recognition on a windows Vista machine...
Does anyone know what would happen if I tried it on a different O.S. What if I ran the script in a windows XP or 98 on Microsoft Virtual PC? I think that's what I'll try and see what happens...
•
•
Join Date: Aug 2007
Posts: 59
Reputation:
Solved Threads: 0
Okay, here's the code after I cleaned it up a bit. The computer's TTS still isn't giving any output whenever I say a phrase, like "Hello Aelita."
The words come up on MSR, so I know it recognized what I said, but there still no speech, other than "Started Sucesfully" at the beginning when I first run the script. After that, my computer's completely silent. I'm still skeptical that I'm using the right syntax for when the computer's supposed to recognize my phrase and say something. Right now I'm typing "if RecognitionType == ("Hello Aelita")" and I don't think 'RecognitionType' is the right command word for it. Does this script work on anyone elses PC?
Python Syntax (Toggle Plain Text)
#Test Script for computer virtual personality. #Credits to Inigo Surguy (inigosurguy@hotmail.com) and Peter Parente for original #Speech Recognition and TTS scripts. #Further commentary by Surguy from win32com.client import constants import win32com.client import pythoncom import time """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://www.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 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) if __name__=='__main__': wordsToAdd = [ "Hello Aelita", "Fine", "Good", "Great", "Wonderful", "How are you?", "Not well", "Awful", "Bad", "Not good", "Not too well", "Thank you", "Thanks", "Time" ] speechReco = SpeechRecognition(wordsToAdd) while 1: pythoncom.PumpWaitingMessages() if RecognitionType == ("Hello Aelita"): self.say("Hello, Loren. How are you today?") if RecognitionType == ("Fine") or ("Great") or ("Wonderful") or ("Good"): say("Great") say("Is there anything I can do for you?") if RecognitionType == ("Not well") or ("Awful") or ("Bad") or ("Not Good") or ("Not too well"): say("That's too bad") say("If there's anything or need, just let me know.") if RecognitionType == ("Time"): say("The time is " + time.asctime(),)
•
•
Join Date: Jul 2006
Posts: 608
Reputation:
Solved Threads: 150
I'm completely out of my waters -- I've never even used Vista (waiting for SP 2 to work out the bugs...).
That said, this looks iffy to me:
Shouldn't it be 'self.say' for all of those?
Jeff
That said, this looks iffy to me:
Python Syntax (Toggle Plain Text)
if RecognitionType == ("Hello Aelita"): self.say("Hello, Loren. How are you today?") if RecognitionType == ("Fine") or ("Great") or ("Wonderful") or ("Good"): say("Great") say("Is there anything I can do for you?") if RecognitionType == ("Not well") or ("Awful") or ("Bad") or ("Not Good") or ("Not too well"): say("That's too bad") say("If there's anything or need, just let me know.") if RecognitionType == ("Time"): say("The time is " + time.asctime(),)
Shouldn't it be 'self.say' for all of those?
Jeff
•
•
Join Date: Aug 2007
Posts: 59
Reputation:
Solved Threads: 0
Your right, I guess it should've been self.say.
But anyhow, I've downloaded a more useful python desktop Speech Recognition code that I seemed to have neglected on the same website from Inigo Surguy. It not only has a more useful python script, but part of the code allows you to edit your own commands and macros into the speech recognition database.
Now here's an interesting discovery I've made. I added "Hello Aelita" to the list of recognizeable words with the command "tts.Speak('Hello, Loren. How are you today?")" in the actions window, or whatever you call it. Now, when I click on the Test button to see if it works, I get the computer's voice "Hello, Loren. How are you toady." But whenever I speak "Hello Aelita" the computer still recognizes the words, but there's no voice? Which is very interesting.
I think I'll download python and the necessary requirements to run the script onto my XP desktop computer and see if I get better results.
But anyhow, I've downloaded a more useful python desktop Speech Recognition code that I seemed to have neglected on the same website from Inigo Surguy. It not only has a more useful python script, but part of the code allows you to edit your own commands and macros into the speech recognition database.
Now here's an interesting discovery I've made. I added "Hello Aelita" to the list of recognizeable words with the command "tts.Speak('Hello, Loren. How are you today?")" in the actions window, or whatever you call it. Now, when I click on the Test button to see if it works, I get the computer's voice "Hello, Loren. How are you toady." But whenever I speak "Hello Aelita" the computer still recognizes the words, but there's no voice? Which is very interesting.
I think I'll download python and the necessary requirements to run the script onto my XP desktop computer and see if I get better results.
•
•
Join Date: Aug 2007
Posts: 59
Reputation:
Solved Threads: 0
Jrcagle, I think you're right about the TTS module not working like I want it to. Apparently, anytime I type in: tts.Speak("Blah, blah, blah"), in the interactive window, I get a response. The speakers will play a TTS Voice that says, "Blah, blah, blah." But whenever I add it to the speech recognition list of words to recognize and speak "Hello Aelita" into the microphone, nothing. It plays the voice when I click Test, so in Theory it should be working perfectly. But I never get anything when I speak into the microphone.
But check this out. I added google to the list of words to be recognized. I then added "browseTo("www.google.com")" to the actions window. when I spoke "google" into the microphone, wahlah! It went to google just like I wanted it to. So I know its not my vista computer. At least, I think.
So I typed in "help(tts.Speak)", like you told me to, jrcagle. I got a reply, but its half greek to me. I got this:
I'm still a python newbie: a get a very rough idea of what it means, but I'm still not at a level where I can take that information and find out how to make my computer talk to me like it should. If this is more of a speech recognition to TTS issue rather than python, does anyone know where I can go to learn how to fix this?
But check this out. I added google to the list of words to be recognized. I then added "browseTo("www.google.com")" to the actions window. when I spoke "google" into the microphone, wahlah! It went to google just like I wanted it to. So I know its not my vista computer. At least, I think.
So I typed in "help(tts.Speak)", like you told me to, jrcagle. I got a reply, but its half greek to me. I got this:
Python Syntax (Toggle Plain Text)
Help on method Speak in module pyTTS.sapi: Speak(self, text, *flags) method of pyTTS.sapi.SynthAndOutput instance Speaks text with the optional flag modifiers. Text can include XML commands.
I'm still a python newbie: a get a very rough idea of what it means, but I'm still not at a level where I can take that information and find out how to make my computer talk to me like it should. If this is more of a speech recognition to TTS issue rather than python, does anyone know where I can go to learn how to fix this?
•
•
Join Date: Aug 2007
Posts: 59
Reputation:
Solved Threads: 0
Yipee! I got it to work!
Here's what I did. I not only loaded the direct speech object in makepython, but I also applied the direct speech recognition. Also, I had to make sure that I had the interactive window selected, otherwise, nothing would happen.
Thanks for your help. Now to move on with my robot!
Here's what I did. I not only loaded the direct speech object in makepython, but I also applied the direct speech recognition. Also, I had to make sure that I had the interactive window selected, otherwise, nothing would happen.
Thanks for your help. Now to move on with my robot!
•
•
Join Date: Aug 2007
Posts: 59
Reputation:
Solved Threads: 0
Sorry, long post.
Okay, it's been a while since I've tested the code on my laptop computer. Since the actual
construction on my autonomous robot is to begin very soon, I've been experimenting with the actual code that's going to go into the robot.
I know there's something wrong with my code because it keeps raising an exception:
Which is puzzling because isn't (self) supposed to be a natural, integrated part of the python programming language?
Here is my code. Once again, I make use of Inigo Surguy's speech recognition sample code, and some sample code from Christian Wyglendowski's timer scripts.
Here's how it's supposed to work:
My robot, Nina, understands serveral words in a human-interaction vocabulary (wordsToAdd). While Nina is waiting for things to be said to her (pythoncom.PumpWaitingMessages), there are two things that are availiable to say: Hello Nina, and What time is it. When you say "Hello Nina" Nina responds by saying hello and asking how you're doing. From that point on, you can only say six responses for how you're doing, 3 positive and 3 negative.
Timing is supposed to be an important part of Nina's interaction with Humans. When you say, hello Nina, and the Greeting stance is on, Nina waits ten seconds for you to respond, otherwise she "gets bored" and assumes she's not talking to anyone anymore, to put it in personified terms...
First off, anyone know how to fix that bizzare exception? Secondly, while I'm working at it, anyone have any pointers to polish up this script? I'd greatly appreciat any help.
Okay, it's been a while since I've tested the code on my laptop computer. Since the actual
construction on my autonomous robot is to begin very soon, I've been experimenting with the actual code that's going to go into the robot.
I know there's something wrong with my code because it keeps raising an exception:
Python Syntax (Toggle Plain Text)
Traceback (most recent call last): File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 305, in RunScript debugger.run(codeObject, __main__.__dict__, start_stepping=1) File "C:\Python25\Lib\site-packages\pythonwin\pywin\debugger\__init__.py", line 60, in run _GetCurrentDebugger().run(cmd, globals,locals, start_stepping) File "C:\Python25\Lib\site-packages\pythonwin\pywin\debugger\debugger.py", line 631, in run exec cmd in globals, locals File "C:\Users\Owner\Desktop\Nina Interaction.py", line 109, in <module> "What time is it" : "speaker.Speak('The time is ' + time.asctime)"} NameError: name 'self' is not defined
Which is puzzling because isn't (self) supposed to be a natural, integrated part of the python programming language?
Here is my code. Once again, I make use of Inigo Surguy's speech recognition sample code, and some sample code from Christian Wyglendowski's timer scripts.
Python Syntax (Toggle Plain Text)
# A code to Interact with an autonomous robot called Nina. # Modified from Inigo Surguy's sample code for speech recognition # and the timer sample scripts by Christian Wyglendowski (http://mail.python.org/pipermail/tutor/2004-November/033333.html) # Further commentary by Surguy. # Sample code for speech recognition using the MS Speech API # Inigo Surguy (inigosurguy@hotmail.com) import time import threading class Timer(threading.Thread): def __init__(self, seconds): self.runTime = seconds threading.Thread.__init__(self) def run(self): time.sleep(self.runTime) class GreetingTimer(Timer): def run(self): counter = self.runTime for sec in range(self.runTime): time.sleep(1.0) counter -= 1 Greeting = 0 GT = GreetingTimer(10) Greeting = 0 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://www.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 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) def SetItems(self): self.items = pickle.load(open(self.SAVE_FILENAME)) while Greeting == 1: self.items = {"Fine" : "self.say('That's good to hear!'); Greeting = 0", "Great" : "self.say('Fantasic!'); Greeting = 0", "Wonderful" : "self.say('That's spectacular'); Greeting = 0", "Not Good" : "self.say('That's too bad'); Greeting = 0", "Terrible" : "speaker.Speak('I'm sorry'); Greeting = 0", "Awful" : "speaker.Speak('Oh I'm very sorry'); Greeting = 0"} if __name__=='__main__': wordsToAdd = [ "Hello Nina", "Fine", "Great", "Wonderful", "Not Good", "Terrible", "Awful", "What time is it"] speechReco = SpeechRecognition(wordsToAdd) while 1: pythoncom.PumpWaitingMessages() self.items = {"Hello Nina" : "Greeting = 1; GT.start", "What time is it" : "speaker.Speak('The time is ' + time.asctime)"}
Here's how it's supposed to work:
My robot, Nina, understands serveral words in a human-interaction vocabulary (wordsToAdd). While Nina is waiting for things to be said to her (pythoncom.PumpWaitingMessages), there are two things that are availiable to say: Hello Nina, and What time is it. When you say "Hello Nina" Nina responds by saying hello and asking how you're doing. From that point on, you can only say six responses for how you're doing, 3 positive and 3 negative.
Timing is supposed to be an important part of Nina's interaction with Humans. When you say, hello Nina, and the Greeting stance is on, Nina waits ten seconds for you to respond, otherwise she "gets bored" and assumes she's not talking to anyone anymore, to put it in personified terms...
First off, anyone know how to fix that bizzare exception? Secondly, while I'm working at it, anyone have any pointers to polish up this script? I'd greatly appreciat any help.
![]() |
Similar Threads
- Arabic speech recognition (C#)
- Microsoft Office 2007 Speech Recognition (Windows Software)
- j2me/Speech Recognition (IT Professionals' Lounge)
- J2me Speech recognition (Java)
- Speech recognition (C++)
- Speech Engine problem (Windows NT / 2000 / XP)
- .NET Speech SDK for ASP.NET (ASP.NET)
Other Threads in the Python Forum
- Previous Thread: pygame: click and picture appears
- Next Thread: Pygame + Python Keyboard Input Problem
| Thread Tools | Search this Thread |
abrupt ansi anti apache approximation array assignment avogadro backend beginner binary bluetooth book builtin calculator character code converter countpasswordentry curved customdialog dan08 dictionaries dictionary dynamic examples exe file float format function gnu graphics gui heads homework ideas import inches input java launcher library line lines linux list lists loop mouse mysqlquery number numbers numeric output parsing path phonebook plugin pointer port prime programming progressbar projects py2exe pygame python random recursion redirect scrolledtext software statictext statistics string strings sum table terminal text textarea thread threading time tlapse trick tricks tuple tutorial twoup ubuntu unicode urllib urllib2 variable wordgame write wxpython xlib





