User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the Python section within the Software Development category of DaniWeb, a massive community of 430,118 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,318 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our Python advertiser: Programming Forums
Views: 1065 | Replies: 22
Reply
Join Date: Aug 2007
Posts: 55
Reputation: Seagull One is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Seagull One Seagull One is offline Offline
Junior Poster in Training

A.I.--Self Programming and Artificial 'Learning'

  #1  
Jul 24th, 2008
Hello again, everybody.

Now that I've just about learned all I can for programming my robot with 'smarts' (I think), I think I'm ready for a bigger challenge: Having my robot program aspects of itself.

Right now I'm going to try to implement it into my robot's human socialization program. After downloading a python script for the English Dictionary, which I found in Projects for the Beginner, I'm going to sort the words by noun, verb, etc, and then, when the robot is listening for chat, she'll get the sentence through the listening, prepare a verbal response (for example by replacing 'I' with 'you' and 'my' with 'your') and say it out loud through text to speech. It won't be perfect, I know, but I can't resist.

I've bookmarked a few tutorials from which I'll implement, but a few things I'd like to ask on top of that:

I want to learn the right syntax for engaging the 'dictation' part of the window's speech recognition, so my robot can listen for any word, pre-put together in the python english dictionary, and then manipulate the sentence and formulate her response.

Also, is there a way I could do a mix between the two: by that I mean pre-built sentences for understanding and the GetSentence function? For instance, I have a prebuilt sentence to recognize, "I'd like you to meet" and I'd like the program to "wait" for a name to catch, like, "Sarah," before saying, "Pleased to meet you, Sarah..." I've tried some experimentation with this, but right after I say "I'd like you to meet" it immediatle comes up with an error that basically says the value for the name of the person has no attribute, without waiting for me to say the name.

I'll be experimenting in the meantime. Any input would be greatly appreciated. Thanks!
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Aug 2007
Posts: 55
Reputation: Seagull One is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Seagull One Seagull One is offline Offline
Junior Poster in Training

Re: A.I.--Self Programming and Artificial 'Learning'

  #2  
Jul 25th, 2008
Okay, I'm trying my experiment in a separate code, scaled down a bit for a prototype script.

Here's what I got so far.

  1. import re
  2. import sys, time, math, string, win32com.client,win32event,pythoncom
  3. from win32com.client import constants
  4. import win32com
  5. import cPickle, zlib
  6.  
  7. import string
  8. import pickle
  9. import win32api
  10. import win32com.client
  11. import traceback
  12.  
  13. import threading
  14. import random
  15.  
  16. speaker = win32com.client.Dispatch("SAPI.SpVoice")
  17.  
  18. def say(text):
  19. speaker.Speak(text)
  20.  
  21. def multiwordReplace(text, wordDic):
  22. rc = re.compile('|'.join(map(re.escape, wordDic)))
  23. def translate(match):
  24. return wordDic[match.group(0)]
  25. return rc.sub(translate, text)
  26.  
  27. wordDic = {
  28. 'you' : 'me',
  29. 'I' : 'you',
  30. 'mine' : 'yours',
  31. 'my' : 'your', }
  32.  
  33. class ContextEvents(win32com.client.getevents("SAPI.SpSharedRecoContext")):
  34. def OnRecognition(self, StreamNumber, StreamPosition, RecognitionType, Result):
  35. newResult = win32com.client.Dispatch(Result)
  36. speaker.Speak(multiwordReplace(GetText.wordDic))

This is what I want to happen in sudo code:

listen for voice

if something is said:
        get text
        replace words according to wordDic
        speak text with replaced wording

if vocalization not understood:
        speak "I'm sorry, what was that?"

This is the first step. I later intent to have my robot 'learn' new words via dictation. A word document with the words of the English language will pre-existant on the system. The plan is to ulimately acheive a human interactor to 'define' knew words, if the robot asks for them, and then have the robot say something like "I see, cheese is a dairy product!" and then save that string to a list preserved for 'learning' new items, and then save the updated python script (so everytime she's powered down her memory doesn't get wiped). That's on the horizon, though.

One muddling road block I've encountered so far with this scaled down version of the script:

Every time I run the program, the python editor seems to close it immediately. Then it names the directory its under and then says "returned exit code 0." Anyone know what this means?

Thanks
Last edited by vegaseat : Aug 11th, 2008 at 4:49 pm. Reason: modified code tags to [code=python]
Reply With Quote  
Join Date: Aug 2007
Posts: 55
Reputation: Seagull One is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Seagull One Seagull One is offline Offline
Junior Poster in Training

Re: A.I.--Self Programming and Artificial 'Learning'

  #3  
Jul 27th, 2008
Okay, I know what's happening now. The program goes through all the code, and once it's done, its done. (I should've seen that... )

Okay, I'm now modifying Inigo Surgui's speech recognition script, replacing some things and adding some others:

  1. from win32com.client import constants
  2. import win32com.client
  3. import pythoncom
  4. import re
  5.  
  6. def multiwordReplace(text, wordDic):
  7. rc = re.compile('|'.join(map(re.escape, wordDic)))
  8. def translate(match):
  9. return wordDic[match.group(0)]
  10. return rc.sub(translate, text)
  11.  
  12. wordDic = {
  13. 'you' : 'me',
  14. 'I' : 'you',
  15. 'mine' : 'yours',
  16. 'my' : 'your' }
  17.  
  18. """Sample code for using the Microsoft Speech SDK 5.1 via COM in Python.
  19. Requires that the SDK be installed; it's a free download from
  20. http://microsoft.com/speech
  21. and that MakePy has been used on it (in PythonWin,
  22. select Tools | COM MakePy Utility | Microsoft Speech Object Library 5.1).
  23.  
  24. After running this, then saying "One", "Two", "Three" or "Four" should
  25. display "You said One" etc on the console. The recognition can be a bit
  26. shaky at first until you've trained it (via the Speech entry in the Windows
  27. Control Panel."""
  28. class SpeechRecognition:
  29. """ Initialize the speech recognition with the passed in list of words """
  30. def __init__(self, wordsToAdd):
  31. # For text-to-speech
  32. self.speaker = win32com.client.Dispatch("SAPI.SpVoice")
  33. # For speech recognition - first create a listener
  34. self.listener = win32com.client.Dispatch("SAPI.SpSharedRecognizer")
  35. # Then a recognition context
  36. self.context = self.listener.CreateRecoContext()
  37. # which has an associated grammar
  38. self.grammar = self.context.CreateGrammar()
  39. # Do not allow free word recognition - only command and control
  40. # recognizing the words in the grammar only
  41. self.grammar.DictationSetState(0)
  42. # Create a new rule for the grammar, that is top level (so it begins
  43. # a recognition) and dynamic (ie we can change it at runtime)
  44. self.wordsRule = self.grammar.Rules.Add("wordsRule",
  45. constants.SRATopLevel + constants.SRADynamic, 0)
  46. # Clear the rule (not necessary first time, but if we're changing it
  47. # dynamically then it's useful)
  48. self.wordsRule.Clear()
  49. # And go through the list of words, adding each to the rule
  50. [ self.wordsRule.InitialState.AddWordTransition(None, word) for word in wordsToAdd ]
  51. # Set the wordsRule to be active
  52. self.grammar.Rules.Commit()
  53. self.grammar.CmdSetRuleState("wordsRule", 1)
  54. # Commit the changes to the grammar
  55. self.grammar.Rules.Commit()
  56. # And add an event handler that's called back when recognition occurs
  57. self.eventHandler = ContextEvents(self.context)
  58. # Announce we've started using speech synthesis
  59. self.say("Started successfully")
  60. """Speak a word or phrase"""
  61. def say(self, phrase):
  62. self.speaker.Speak(phrase)
  63.  
  64.  
  65. """The callback class that handles the events raised by the speech object.
  66. See "Automation | SpSharedRecoContext (Events)" in the MS Speech SDK
  67. online help for documentation of the other events supported. """
  68. class ContextEvents(win32com.client.getevents("SAPI.SpSharedRecoContext")):
  69. """Called when a word/phrase is successfully recognized -
  70. ie it is found in a currently open grammar with a sufficiently high
  71. confidence"""
  72. def OnRecognition(self, StreamNumber, StreamPosition, RecognitionType, Result):
  73. newResult = win32com.client.Dispatch(Result)
  74. say("So",newResult.PhraseInfo.GetText(multiwordreplace))
  75.  
  76. if __name__=='__main__':
  77. wordsToAdd = [ "My", "Name", "is", "Loren" ]
  78. speechReco = SpeechRecognition(wordsToAdd)
  79. while 1:
  80. pythoncom.PumpWaitingMessages()

The goal of the experiment is to be able to say something like , "My name is Loren." And then have the robot catch that string, replace a few words and reply, "So, your name is Loren" That's what I'm shooting for so far.

Now, new problem. I get this error message the moment I say "My":

pythoncom error: Python error invoking COM method.

Traceback (most recent call last):
  File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line 285, in _Invoke_
    return self._invoke_(dispid, lcid, wFlags, args)
  File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line 290, in _invoke_
    return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None)
  File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line 593, in _invokeex_
    return func(*args)
  File "C:\Users\Loren\Desktop\My Robots\Experimental Code!\Prototype Script B.py", line 74, in OnRecognition
    say("So",newResult.PhraseInfo.GetText(multiwordreplace))
<type 'exceptions.NameError'>: global name 'say' is not defined

Not sure what's going wrong. Because "say" is defined earlier in the script.
Anyone's input would be appreciated. I'll continue experimentation on my end.

Thanks!
Last edited by vegaseat : Aug 11th, 2008 at 4:51 pm. Reason: modified code tags to [code=python]
Reply With Quote  
Join Date: Aug 2007
Posts: 55
Reputation: Seagull One is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Seagull One Seagull One is offline Offline
Junior Poster in Training

Re: A.I.--Self Programming and Artificial 'Learning'

  #4  
Jul 27th, 2008
New Progress, everyone.

I've been doing my research and I think I'm getting close to acheiving phase 1 of my artificial 'Learning' project. Here's the script I've put together, after some studying, tinkering and debugging:

  1. from win32com.client import constants
  2. import win32com.client
  3. import re
  4.  
  5. listening = True
  6.  
  7. class SpeechRecognition:
  8. def __init__(self, str1):
  9. self.speaker = win32com.client.Dispatch("SAPI.SpVoice")
  10. self.listener = win32com.client.Dispatch("SAPI.SpSharedRecognizer")
  11. self.context = self.listener.CreateRecoContext()
  12. self.grammar = self.context.CreateGrammar()
  13. self.eventHandler = ContextEvents(self.context)
  14. self.say("I am listening for you master")
  15. def say(self, phrase):
  16. self.speaker.Speak(phrase)
  17. def sentence(self, text):
  18. self.GetText()
  19.  
  20. class ContextEvents(win32com.client.getevents("SAPI.SpSharedRecoContext")):
  21. def OnRecognition(self, StreamNumber, StreamPosition, RecognitionType, Result):
  22. newResult = win32com.client.Dispatch(Result)
  23. IHeardYou = True
  24.  
  25. while listening == True:
  26. str1 = SpeechRecognition.sentence(text)
  27. str2 = multiwordReplace(str1, wordDic)
  28. if IHeardYou == True:
  29. say(str2)
  30. IHeardYou = False
  31.  
  32. def multiwordReplace(text, wordDic):
  33. rc = re.compile('|'.join(map(re.escape, wordDic)))
  34. def translate(match):
  35. return wordDic[match.group(0)]
  36. return rc.sub(translate, text)
  37.  
  38. wordDic = {
  39. 'my': 'your',
  40. 'you': 'me',
  41. 'mine': 'yours',
  42. 'your': 'my',
  43. 'yours': 'mine',
  44. 'me': 'you',
  45. 'I' : 'you' }

The main problem I'm encountering with this one: I get this exception when I try to run the script.

Traceback (most recent call last):
  File "C:\Python25\Lib\site-packages\pythonwin\pywin\framework\scriptutils.py", line 310, in RunScript
    exec codeObject in __main__.__dict__
  File "C:\Users\Loren\Desktop\My Robots\Experimental Code!\Prototype Script C.py", line 26, in <module>
    str1 = SpeechRecognition.sentence(text)
NameError: name 'text' is not defined

for me, its a puzzling exception, because 'text' is defined in the class 'SpeechRecognition' under 'sentence' and I think I calling that function on line 26...but I must be doing something wrong.

Can anyone point out my flaw? In the meantime, I'll be trying to find it myself...

Thanks
Last edited by vegaseat : Aug 11th, 2008 at 4:52 pm. Reason: modified code tags to [code=python]
Reply With Quote  
Join Date: Aug 2007
Posts: 55
Reputation: Seagull One is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Seagull One Seagull One is offline Offline
Junior Poster in Training

Re: A.I.--Self Programming and Artificial 'Learning'

  #5  
Jul 28th, 2008
Okay, I've decided to start with something even simpler--making one modification to Inigo Surgui's speech recognition recipe:

  1. from win32com.client import constants
  2. import win32com.client
  3. import pythoncom
  4.  
  5. """Sample code for using the Microsoft Speech SDK 5.1 via COM in Python.
  6. Requires that the SDK be installed; it's a free download from
  7. http://microsoft.com/speech
  8. and that MakePy has been used on it (in PythonWin,
  9. select Tools | COM MakePy Utility | Microsoft Speech Object Library 5.1).
  10.  
  11. After running this, then saying "One", "Two", "Three" or "Four" should
  12. display "You said One" etc on the console. The recognition can be a bit
  13. shaky at first until you've trained it (via the Speech entry in the Windows
  14. Control Panel."""
  15. class SpeechRecognition:
  16. """ Initialize the speech recognition with the passed in list of words """
  17. def __init__(self, wordToAdd):
  18. # For text-to-speech
  19. self.speaker = win32com.client.Dispatch("SAPI.SpVoice")
  20. # For speech recognition - first create a listener
  21. self.listener = win32com.client.Dispatch("SAPI.SpSharedRecognizer")
  22. # Then a recognition context
  23. self.context = self.listener.CreateRecoContext()
  24. # which has an associated grammar
  25. self.grammar = self.context.CreateGrammar()
  26. # Do not allow free word recognition - only command and control
  27. # recognizing the words in the grammar only
  28. self.grammar.DictationSetState(0)
  29. # Create a new rule for the grammar, that is top level (so it begins
  30. # a recognition) and dynamic (ie we can change it at runtime)
  31. self.wordsRule = self.grammar.Rules.Add("wordsRule",
  32. constants.SRATopLevel + constants.SRADynamic, 0)
  33. # Clear the rule (not necessary first time, but if we're changing it
  34. # dynamically then it's useful)
  35. self.wordsRule.Clear()
  36. # And go through the list of words, adding each to the rule
  37. [ self.wordsRule.InitialState.AddWordTransition(None, word) for word in wordsToAdd ]
  38. # Set the wordsRule to be active
  39. self.grammar.Rules.Commit()
  40. self.grammar.CmdSetRuleState("wordsRule", 1)
  41. # Commit the changes to the grammar
  42. self.grammar.Rules.Commit()
  43. # And add an event handler that's called back when recognition occurs
  44. self.eventHandler = ContextEvents(self.context)
  45. # Announce we've started using speech synthesis
  46. self.speaker.Speak("Started successfully")
  47. """Speak a word or phrase"""
  48.  
  49. """The callback class that handles the events raised by the speech object.
  50. See "Automation | SpSharedRecoContext (Events)" in the MS Speech SDK
  51. online help for documentation of the other events supported. """
  52. class ContextEvents(win32com.client.getevents("SAPI.SpSharedRecoContext")):
  53. """Called when a word/phrase is successfully recognized -
  54. ie it is found in a currently open grammar with a sufficiently high
  55. confidence"""
  56. def say(self, phrase):
  57. self.speaker.Speak(phrase)
  58. def OnRecognition(self, StreamNumber, StreamPosition, RecognitionType, Result):
  59. newResult = win32com.client.Dispatch(Result)
  60. print "You said",newResult.PhraseInfo.GetText()
  61.  
  62. if __name__=='__main__':
  63. wordsToAdd = [ "One", "Two", "Three", "Four" ]
  64. speechReco = SpeechRecognition(wordsToAdd)
  65. while 1:
  66. pythoncom.PumpWaitingMessages()

All I'm trying to do for this test is switch this bit of code on line 60:

print "You said",newResult.PhraseInfo.GetText()

to this:

say("You said",newResult.PhraseInfo.GetText())

But here's what I get the moment I say "One":

pythoncom error: Python error invoking COM method.

Traceback (most recent call last):
  File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line 285, in _Invoke_
    return self._invoke_(dispid, lcid, wFlags, args)
  File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line 290, in _invoke_
    return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None)
  File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line 593, in _invokeex_
    return func(*args)
  File "C:\Users\Loren\Desktop\My Robots\SpeechRecognition.py", line 60, in OnRecognition
    say("You said",newResult.PhraseInfo.GetText())
<type 'exceptions.NameError'>: global name 'say' is not defined

from what I understand, 'say' is defined under ContextEvents, the same class under which 'OnRecognition' is defined. So 'say' should be local right?

By the way, I've tried using the global statement before 'say' but that didn't seem to work either.

I've spent hours and hours trying to solve this simple problem but to no avail...
Now I really stumped

Can anyone give me any input? I'd really appreciate it.
Last edited by vegaseat : Aug 11th, 2008 at 4:51 pm. Reason: modified code tags to [code=python]
Reply With Quote  
Join Date: Jul 2008
Location: Durham, NC
Posts: 213
Reputation: jlm699 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 32
jlm699's Avatar
jlm699 jlm699 is offline Offline
Posting Whiz in Training

Re: A.I.--Self Programming and Artificial 'Learning'

  #6  
Jul 28th, 2008
Yes, it is defined within the same class but not in the scope of the function OnRecognition. say() is a member of the ContextEvents class so you'll need to call it as self.say()
Let's Go Pens!

** Just because I reply to your question does not invite you to PM me. Keep discussions on the thread of topic, I will not answer your questions over PM. **
Reply With Quote  
Join Date: Aug 2007
Posts: 55
Reputation: Seagull One is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Seagull One Seagull One is offline Offline
Junior Poster in Training

Re: A.I.--Self Programming and Artificial 'Learning'

  #7  
Jul 28th, 2008
Okay I think I see now, jlm669. Thanks.

But now its saying this when I say one:

Traceback (most recent call last):
  File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line 285, in _Invoke_
    return self._invoke_(dispid, lcid, wFlags, args)
  File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line 290, in _invoke_
    return S_OK, -1, self._invokeex_(dispid, lcid, wFlags, args, None, None)
  File "C:\Python25\Lib\site-packages\win32com\server\policy.py", line 593, in _invokeex_
    return func(*args)
  File "C:\Users\Loren\Desktop\My Robots\SpeechRecognition.py", line 60, in OnRecognition
    self.say("You said",newResult.PhraseInfo.GetText())
<type 'exceptions.TypeError'>: say() takes exactly 2 arguments (3 given)

Okay, let me see if I can identify this problem visually: the problem starts when the script runs the line: self.say("You said",newResult.PhraseInfo.Get())

am I right?

The problem is that the function 'say' only takes 2 arguments, which are "self and phrase," right? But three arguments are given in the line: self.say("You said",newResult.PhraseInfo.GetText()) So basically, there's an argument I need to add to the function 'say' to make it work. Is this correct? If so, which arguement could that be I wonder...newResult? GetText()? or maybe just text?

By the way, part of my big difficulty learning to program in python is that I can't see how it works visually, so I have trouble identifying the various names of the parts of code (for example, what part of the code is the argument?). I'd program my robot in visual basic, but I've already done tons of it in python and python gives me more possibilities...

If only they had visual python...
Reply With Quote  
Join Date: Aug 2007
Posts: 55
Reputation: Seagull One is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Seagull One Seagull One is offline Offline
Junior Poster in Training

Re: A.I.--Self Programming and Artificial 'Learning'

  #8  
Jul 28th, 2008
Okay, I tinkered around a bit and I fixed it!

The working script now looks like this:

  1. from win32com.client import constants
  2. import win32com.client
  3. import pythoncom
  4.  
  5. """Sample code for using the Microsoft Speech SDK 5.1 via COM in Python.
  6. Requires that the SDK be installed; it's a free download from
  7. http://microsoft.com/speech
  8. and that MakePy has been used on it (in PythonWin,
  9. select Tools | COM MakePy Utility | Microsoft Speech Object Library 5.1).
  10.  
  11. After running this, then saying "One", "Two", "Three" or "Four" should
  12. display "You said One" etc on the console. The recognition can be a bit
  13. shaky at first until you've trained it (via the Speech entry in the Windows
  14. Control Panel."""
  15. class SpeechRecognition:
  16. """ Initialize the speech recognition with the passed in list of words """
  17. def __init__(self, wordsToAdd):
  18. # For text-to-speech
  19. self.speaker = win32com.client.Dispatch("SAPI.SpVoice")
  20. # For speech recognition - first create a listener
  21. self.listener = win32com.client.Dispatch("SAPI.SpSharedRecognizer")
  22. # Then a recognition context
  23. self.context = self.listener.CreateRecoContext()
  24. # which has an associated grammar
  25. self.grammar = self.context.CreateGrammar()
  26. # Do not allow free word recognition - only command and control
  27. # recognizing the words in the grammar only
  28. self.grammar.DictationSetState(0)
  29. # Create a new rule for the grammar, that is top level (so it begins
  30. # a recognition) and dynamic (ie we can change it at runtime)
  31. self.wordsRule = self.grammar.Rules.Add("wordsRule",
  32. constants.SRATopLevel + constants.SRADynamic, 0)
  33. # Clear the rule (not necessary first time, but if we're changing it
  34. # dynamically then it's useful)
  35. self.wordsRule.Clear()
  36. # And go through the list of words, adding each to the rule
  37. [ self.wordsRule.InitialState.AddWordTransition(None, word) for word in wordsToAdd ]
  38. # Set the wordsRule to be active
  39. self.grammar.Rules.Commit()
  40. self.grammar.CmdSetRuleState("wordsRule", 1)
  41. # Commit the changes to the grammar
  42. self.grammar.Rules.Commit()
  43. # And add an event handler that's called back when recognition occurs
  44. self.eventHandler = ContextEvents(self.context)
  45. # Announce we've started using speech synthesis
  46. self.speaker.Speak("Started successfully")
  47. """Speak a word or phrase"""
  48.  
  49. """The callback class that handles the events raised by the speech object.
  50. See "Automation | SpSharedRecoContext (Events)" in the MS Speech SDK
  51. online help for documentation of the other events supported. """
  52. class ContextEvents(win32com.client.getevents("SAPI.SpSharedRecoContext")):
  53. """Called when a word/phrase is successfully recognized -
  54. ie it is found in a currently open grammar with a sufficiently high
  55. confidence"""
  56. def OnRecognition(self, StreamNumber, StreamPosition, RecognitionType, Result):
  57. newResult = win32com.client.Dispatch(Result)
  58. self.speaker = win32com.client.Dispatch("SAPI.SpVoice")
  59. print "You said",newResult.PhraseInfo.GetText()
  60. self.speaker.Speak("You said")
  61. self.speaker.Speak(newResult.PhraseInfo.GetText())
  62.  
  63. if __name__=='__main__':
  64. wordsToAdd = [ "One", "Two", "Three", "Four" ]
  65. speechReco = SpeechRecognition(wordsToAdd)
  66. while 1:
  67. pythoncom.PumpWaitingMessages()

Some minor flaws I noticed with my tinkering, the Voice synthesis starts over everytime I speak a number (I presume because I told it to on line 58. Oh well) Also, I don't know why it wouldn't work if I tried to put in "You said: " So I just separated them into two operations.

Now for the next step! Getting my robot to listen for a string of words, and replacing them!
Last edited by vegaseat : Aug 11th, 2008 at 4:52 pm. Reason: modified code tags to [code=python]
Reply With Quote  
Join Date: Jul 2008
Location: Durham, NC
Posts: 213
Reputation: jlm699 is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 32
jlm699's Avatar
jlm699 jlm699 is offline Offline
Posting Whiz in Training

Re: A.I.--Self Programming and Artificial 'Learning'

  #9  
Jul 28th, 2008
P.S. when you use code tags it helps if you define the language via [code=xxxx] so that syntax highlighting is turned on. This makes it loads easier to read.

[code=python] for this forum (usually)
Let's Go Pens!

** Just because I reply to your question does not invite you to PM me. Keep discussions on the thread of topic, I will not answer your questions over PM. **
Reply With Quote  
Join Date: Aug 2007
Posts: 55
Reputation: Seagull One is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
Seagull One Seagull One is offline Offline
Junior Poster in Training

Re: A.I.--Self Programming and Artificial 'Learning'

  #10  
Jul 29th, 2008
Thanks Jlm699. I'll do that from now on.

Loren
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb Python Marketplace