Seagull One 0 Junior Poster in Training

I've been working hard all day to get this to work.

I'm playing around with the math module in python. I eventually want the following code to help me control the speed of a servo motor. The idea is to get the servo speed to accelerate and then decelerate as it reaches its set position--in a parabolic way you might say.

The problem is I'm getting wavy numbers apparently from the algorithm I've set up and it needs to be a nice smooth transition.

from __future__ import division
import math
import time

def Interpolation():
    EffectPercentage = 1
    Step = 1
    nSteps = 32
    MovementStepPercentage = EffectPercentage/nSteps*Step
    print MovementStepPercentage
    while Step << 32:
        Interpolation = (1-math.sin(MovementStepPercentage*180+90))/2*EffectPercentage+MovementStepPercentage*(1-EffectPercentage)
        print "Interpolation =", Interpolation
        Step = Step+1
        print "Step =", Step
        MovementStepPercentage = EffectPercentage/nSteps*Step
        print MovementStepPercentage
        time.sleep(0.0035)
        if Step == 32:
            break

Interpolation()

I know a thing or two about math, but not enough to get this to work apparently... any pointers?

Seagull One 0 Junior Poster in Training

I'm working with some code to have a robot do vision processing, speech recognition and text-to-speech.

I'm using python2.6 and openCV

The objective of the code is to have the robot recognize faces via webcam and say, "Hello."

It does this more or less perfectly, except for one thing.

A problem I'm encountering - it's more like an inconvenience - is when Text-to-speech starts talking, the python code doesn't process anything until its finished talking. So when my robot says "hello" the vision processing freezes up and doesn't continue until after its done talking. This concerns me because if I - or someone interacting with my robot - moves from one corner to another, the robot could lose track of where it's operator's face is. It isn't just with vision processing either. The same is true for servo motor movement. I've tested it...

So I'm wondering, is there any way to have the text to speech and the vision processing as separate elements? Basically, is there any way text-to-speech can function without pausing the rest of the python script? Can it run as a separate element, sort of like two things running at the same time so the process isn't effected?

I'm implementing the speech.py module to do my voice recognition and text-to-speech.

Any help would be much appreciated.

Thanks.

Seagull One 0 Junior Poster in Training

Thanks for the tips, xav.vijay!

The code is working and I'm getting some stereo vision responses from my robot!

Seagull One 0 Junior Poster in Training

Okay, I tried that, but now I'm getting this:

Width:  160 Height:  120
IMAGE_COUNT = 274

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\RoboRealm\API\API\Python\SteroTestNINA.py", line 291, in <module>
    Z_Actual = (11 * 5.5)/float(COGXL)-float(COGXR)
ValueError: empty string for float()
Seagull One 0 Junior Poster in Training

Yes.

Apparently, COGXR equals "33"

Here's what it looks like before the exception is raised

Width:  160 Height:  120
IMAGE_COUNT = 541
33
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\RoboRealm\API\API\Python\SteroTestNINA.py", line 291, in <module>
    Z_Actual = (11 * 5.5)/COGXL-COGXR
TypeError: unsupported operand type(s) for /: 'float' and 'str'

Any ideas what's wrong?

Seagull One 0 Junior Poster in Training

I'm writing some code for my robot's stereoscopic vision.

This is how I'm calculating the stereo vision in python (I'm using the roborealm API).

COGXR = rr.GetVariable("COG_X_RIGHT")
COGYR = rr.GetVariable("COG_Y_RIGHT")
COGXL = rr.GetVariable("COG_X_LEFT")
COGYL = rr.GetVariable("COG_Y_LEFT")

Z_Actual = (11 * 5.5)/COGXL-COGXR
X_Actual = (COGXL*Z_Actual)/(5.5)
Y_Actual = (COGYL*Z_Actual)/(5.5)

Whenever I run the program however, I get this error message:

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\RoboRealm\API\API\Python\SteroTestNINA.py", line 289, in <module>
    Z_Actual = (11 * 5.5) / rr.GetVariable("COG_X_LEFT") - rr.GetVariable("COG_X_RIGHT")
TypeError: unsupported operand type(s) for /: 'float' and 'str'

This doesn't make much sense to me because COGXR and COGXL are not actually float or string variables. They come up as integers whenever I "print" them regularly. But for some reason when I stick them in an equation like this it wants to treat it as a float or a string.

Any idea's what I'm doing wrong?

BTW, haven't been to daniweb in a while

Seagull One 0 Junior Poster in Training

Thanks vkumar42! Here's what the code looks like now. It works great!

import speech
import random
import pythoncom

running = True

class OnTopic:
    topic = "nothing"

    def TopicChange(self):
        self.topic = "nothing"

print OnTopic.topic        

def RapYoung():
    speech.say("Did you know raptors took good care of their young")
    OnTopic.topic = "raptors young"
    print OnTopic.topic
def RapFeathers():
    speech.say("Did you know raptors probably had feathers")
    OnTopic.topic = "raptors feathers"
    print OnTopic.topic

RapFunc = [ RapYoung, RapFeathers ]

def command_callback(phrase, listener):
    if phrase == "tell me about raptors":
        random.choice(RapFunc)()
    if phrase == "yes":
        if OnTopic.topic == "raptors feathers":
            speech.say("Yes. Fossils indicate some of them had feathers")
        elif OnTopic.topic == "raptors young":
            speech.say("Yes. Even cold-blooded predators can have a warm heart")
        else:
            speech.say("Yes what?")

listener1 = speech.listenfor(["tell me about raptors", "yes"], command_callback )

while running == True:
    pythoncom.PumpWaitingMessages()

Thanks again!

Seagull One 0 Junior Poster in Training

I've been doing some more work on my robot today and I'm having a bit of trouble with calling a random function like so:

import speech
import random
import pythoncom

running = 1

class OnTopic:
    topic = "nothing"

    def TopicChange(self):
        self.topic = "nothing"

print OnTopic.topic        

class Know_Raptors:
    def RapYoung(self):
        speech.say("Did you know raptors took good care of their young")
        self.topic = "raptors young"

    def RapFeathers(self):
        speech.say("Did you know raptors probably had feathers")
        self.topic = "raptors feathers"
        
AskRaptor = [ Know_Raptors().RapFeathers(), Know_Raptors().RapYoung() ]
def command_callback(phrase, listener):
    if phrase == "tell me about raptors":
        #Here's where I'm stuck.
        random.choice(AskRaptor)
    if phrase == "yes":
        if self.topic == "raptors feathers":
            speech.say("Yes. Fossils indicate some of them had feathers")
        elif self.topic == "raptors young":
            speech.say("Yes. Even cold-blooded predators can have a warm heart")
        else:
            speech.say("Yes what?")

listener1 = speech.listenfor(["tell me about raptors", "yes"], command_callback )

while running == 1:
    pythoncom.PumpWaitingMessages()

By the way, this is using Michael gundlach's speech module (which is fabulous!)

What I want it to do is when I ask "tell me about raptors," I want my robot to randomly chose one of the two functions in the class Know_Raptors. The problem is when I ask, "tell me about raptors," it registers the phrase but nothing happens.

And besides that, I notice that instead of waiting for me to say "tell me about raptors" my robot goes and says both the functions in order.

I'd make the first line in the function just a string and then put …

Seagull One 0 Junior Poster in Training

Never knew you could do that.

Thank you both!

Loren

Seagull One 0 Junior Poster in Training

I'm finally getting my robot's software off the ground!:) (Although I'm giving my "artificial learning" program a rest for later).

However, here's something I've been wondering how to do for quite some time now.

I'm using the time module to allow my robot to tell me the time upon vocal command. However, when my robot replies, the reply sounds something like this, "The time is currently Monday September eight 12 colon 46 colon 30 colon 2008." My robot vocalizes the "colon" in the time "12:46:30." So I tried to replace all colons with string.replace, like so:

import speech
import random
import sys, time, math, string

string = string.replace(":", " ")

TimeStr = [ "The time is currently " + time.asctime(), "Right now its " + time.asctime(), "It's " + time.asctime(), time.asctime() ]

if phrase == "whats the time":
    speech.say(random.choice(TimeStr))

but that gave an exception saying replace takes at least 3 arguments (2 given).
So after looking up help(replace) in the command line, I found out I had to list the string, so I rewrote the code like this:

import speech
import sys, time, math, string

string = string.replace(time.asctime(),":", " ")

TimeStr = [ "The time is currently " + time.asctime(), "Right now its " + time.asctime(), "It's " + time.asctime(), time.asctime() ]

if phrase == "whats the time":
    speech.say(random.choice(TimeStr))

After that the program runs, but my robot is still vocalizing the "colon" in time.asctime()!

I'm not sure where to go from here...

Seagull One 0 Junior Poster in Training

I did already. Thanks, Micheal ( :

Seagull One 0 Junior Poster in Training

Wow! Thanks Micheal! I'll try out that new version!

Thanks also, Vegaseat. I do intent to get a good microphone (once I have the money) and use that instead of a desktop mic.

As soon as I have my robot complete, (which won't be for a while, but I will get there), maybe I could share a link to some videos or something.

Thanks against everybody!

Loren

Seagull One 0 Junior Poster in Training

Absolutely...um, I'm sorry not sure what you mean by setup. I assumed you mean programming wise so here it goes...:)

While I'm building my robot mechanically, I'm also taking time to work on its programming as well. Right now I'm just experimenting and putting up some test scripts.

The objective of my project right now is just to get a python script that can listen to my voice via the speech module, capture some words via dictation, then change those words around a bit to repeat what I said, but from the robot's first person perspective. For example, if I tell my robot, "I think you are a cool robot," I want my robot to process that recognized phrase, and then repeat, "You think I am a cool robot."

The ultimate goal of the project is to get a fully functional simulated intelligence program to my robot. In this program, my robot starts out its existence with only a limited vocabulary in her python scripting (although she will have a full English dictionary somewhere on the system, so the Windows Vista Speech Recognition will read that and assimilate that into functionality.)

Here's an example of what I want to accomplish ultimately with this A.I. simulation experiment: I tell my robot, "I like cheese." My robot's programming processing this phrase and sees a word not listed in the python script (I intend to use lists to classify words into nouns, verbs, etc. Each word will also have …

Seagull One 0 Junior Poster in Training

Hi Mruane!

I think you and I are working on similar projects! My A.I. Experimentation is for a mobile robot though. I too want to simulate A.I. and learning for my robot, NINA.

Seagull One 0 Junior Poster in Training

Okay.

Thanks to Micheal Gunlach's new speech recognition module, my scripting has become easier to work with!

Here is the next script to test my robot's A.I. and Artificial learning:

#New Speech Recognition for Nina. Speech module provided by Michael Gundlach.
#Thanks, Michael!
import speech
import string

#Define a sentence convention callback everytime dictation text is recognized
def SentenceConvention(phrase, listener):
    #These lists define pronous for my robot to look out for...
    subject_pronouns = [ "you", "he", "she", "I", "it" ]
    subject_pronous_replacement = [ "I", "he", "she", "you", "it" ]
    object_pronouns = [ "you", "him", "her", "me", "it" ]
    object_pronouns_replacement = [ "me", "him", "her", "you", "it" ]
    #now we get to the real processing
    if phrase == "stop please":
        speech.stoplistening(listener)
    else:
        #print what Nina heard
        print "Heard %s" % phrase
        #Now split phrase for analysis
        words = string.split(phrase)
        #count the words
        wordCount = len(words)
        #report back how many words were recognized
        print "I heard you say ", wordCount
        #This is the biggie right here.
        #If the first word in phrase is "I" from the subject pronoun list...
        if words[0] == subject_pronouns[0]:
            #replace "I" with "You" from the list subject_pronouns_replacement
            repeat = phrase.replace(subject_pronouns_replacement[0])
            #now speak the new phrase
            speech.say(repeat)
            #and print it
            print repeat
        

# a callback to run whenever a certain phrase is heard...
def command_callback(phrase, listener):
    if phrase == 'Hello Nina':
        speech.say("Hello Master")
    if phrase == 'How are you today':
        speech.say('Still trying to learn how to speak correctly')
    if phrase == 'Recite the Three Laws of …
Seagull One 0 Junior Poster in Training

Hi Michael.

I don't really use your speech module to move around my consol window. I simply use it for my robot's control, and in that regards in works great.

Thanks for your input on the "phrase" feature. :) However, I'm hoping to write a program that's a little more flexible. You see, I'm working on a program for my robot, Nina, that's will allows humans to 'socialize' with her like a chatbot. But instead of saying specific phrases and having to word your sentences just right, You say anything you want, and my robot is supposed to split the string of the text from your voice and identity the parts of speech (articles, subject pronouns, verbs, object pronouns). Then she takes that string of words from dictation, replaces the subject pronoun from "I" to "You" and the object pronoun from "you" to "me," recompile the list back into a string and echo my sentence, but from her perspective (well, sort of...I mean its a robot *shrug*). Resulting in "You love me."

This is just a basic experiment in my Nina A.I. endeavors. I have a thread for it, where I post my progress and ask for advice. If you're interested in seeing what I've tried so far, or if you have any pointers of your own, you can find it under this thread:

A.I.--self programming and artificial 'learning.'

Thanks again, Micheal!

Loren

Seagull One 0 Junior Poster in Training

Hi Michael,

Your speech module runs fine on my PC.

What I'm trying to do in my script though, is use a command like "phrase.GetText()" so I can turn that spoken text into a string. Then I want to split that string and turn the words into a list, so I can find the individual words, and then replace them with other words.

For instance, if I tell my robot, "I love you" the script would get that text, turn it into a string, find the subject pronoun, "I," replace that with "You" then find the object pronoun "you" and replace that with "me." Then sort the split sentence back into a string and answer using speech.say "You love me"

However, when I try it, it says these so such function that goes with "phrase" as "Get Text".

I typed "help(speech)" after importing it in the command prompt, and it doesn't look like theres a "GetText()" function that goes with "phrase" in your module. Is it in the new version?

Or is there a way to work around it?

Thanks!

Loren

Seagull One 0 Junior Poster in Training

No problem. It's happened to me before too. :P

Seagull One 0 Junior Poster in Training

Oh, yeah... Thanks Jlm699! It works fine now.

Loren

Seagull One 0 Junior Poster in Training

Problem:

I typed in "easy_install speech" in the windows command prompt and indeed it said in wasn't recognized. So I downloaded and ran the python script to install easy install, and that ran fine. So I tried again to typer "easy_install speech" in the windows command prompt, but it still isn't recognizing it.

I tried running the python script again, but it said it was already installed.

Any ideas? I'm running Vista Ultimate. I really would love to try your code, if I can get it running!

Seagull One 0 Junior Poster in Training

:-O

Whoa! That looks really cool! I'll definitely have to try that!

Thanks, Michael! You're brilliant!

Loren

Seagull One 0 Junior Poster in Training

I was thinking the same thing, tzushky.

I'll hit the books and see what I can do. Thanks!

Seagull One 0 Junior Poster in Training

Okay, I've experimened a bit and managed to get my robot to switch a few words around.

My script looks like this:

from win32com.client import constants
import win32com.client
import pythoncom

def multiwordReplace(text, wordDict):
    for key in wordDict:
        text = text.replace(key, wordDict[key])
    return text

wordDict = {
    "you" : "me",
    "I" : "you",
    "yours" : "mine",
    "my" : "your" }

"""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):
        # 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()
        #enable free word recognition
        self.grammar.DictationSetState(1)
        # 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.speaker.Speak("Hello Master. This is Nina. I'm ready for my first lesson.")
    """Speak a word or phrase"""
        
"""The callback class that …
Seagull One 0 Junior Poster in Training

Thanks Jlm699. I'll do that from now on.

Loren

Seagull One 0 Junior Poster in Training

Okay, I tinkered around a bit and I fixed it!

The working script now looks like this:

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 …
Seagull One 0 Junior Poster in Training

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? :confused:

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...:-/

Seagull One 0 Junior Poster in Training

Okay, I've decided to start with something even simpler--making one modification to Inigo Surgui's speech recognition recipe:

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, wordToAdd):
        # 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 …
Seagull One 0 Junior Poster in Training

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:

from win32com.client import constants
import win32com.client
import re

listening = True

class SpeechRecognition:
    def __init__(self, str1):
        self.speaker = win32com.client.Dispatch("SAPI.SpVoice")
        self.listener = win32com.client.Dispatch("SAPI.SpSharedRecognizer")
        self.context = self.listener.CreateRecoContext()
        self.grammar = self.context.CreateGrammar()
        self.eventHandler = ContextEvents(self.context)
        self.say("I am listening for you master")
    def say(self, phrase):
        self.speaker.Speak(phrase)
    def sentence(self, text):
        self.GetText()

class ContextEvents(win32com.client.getevents("SAPI.SpSharedRecoContext")):
    def OnRecognition(self, StreamNumber, StreamPosition, RecognitionType, Result):
        newResult = win32com.client.Dispatch(Result)
        IHeardYou = True
        
while listening == True:
    str1 = SpeechRecognition.sentence(text)
    str2 = multiwordReplace(str1, wordDic)
    if IHeardYou == True:
        say(str2)
        IHeardYou = False

def multiwordReplace(text, wordDic):
    rc = re.compile('|'.join(map(re.escape, wordDic)))
    def translate(match):
        return wordDic[match.group(0)]
    return rc.sub(translate, text)

wordDic = {
    'my': 'your',
    'you': 'me',
    'mine': 'yours',
    'your': 'my',
    'yours': 'mine',
    'me': 'you',
    '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 …

Seagull One 0 Junior Poster in Training

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...:icon_rolleyes: )

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

from win32com.client import constants
import win32com.client
import pythoncom
import re

def multiwordReplace(text, wordDic):
    rc = re.compile('|'.join(map(re.escape, wordDic)))
    def translate(match):
        return wordDic[match.group(0)]
    return rc.sub(translate, text)

wordDic = {
    'you' : 'me',
    'I' : 'you',
    'mine' : 'yours',
    'my' : 'your' }

"""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 …
Seagull One 0 Junior Poster in Training

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.

import re
import sys, time, math, string, win32com.client,win32event,pythoncom
from win32com.client import constants
import win32com
import cPickle, zlib

import string
import pickle
import win32api
import win32com.client
import traceback

import threading
import random

speaker = win32com.client.Dispatch("SAPI.SpVoice")

def say(text):
    speaker.Speak(text)

def multiwordReplace(text, wordDic):
    rc = re.compile('|'.join(map(re.escape, wordDic)))
    def translate(match):
        return wordDic[match.group(0)]
    return rc.sub(translate, text)

wordDic = {
    'you' : 'me',
    'I' : 'you',
    'mine' : 'yours',
    'my' : 'your', }

class ContextEvents(win32com.client.getevents("SAPI.SpSharedRecoContext")):
    def OnRecognition(self, StreamNumber, StreamPosition, RecognitionType, Result):
        newResult = win32com.client.Dispatch(Result)
        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 …

Seagull One 0 Junior Poster in Training

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.:icon_twisted:

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 …

Seagull One 0 Junior Poster in Training

Ugh (head bonk) of course! That's why is says "MyApp" in there.

Okay, I added it under MyApp. It took a little while to debug a few things along the way, but it works great now!

Thanks!

Seagull One 0 Junior Poster in Training

Hello again, everyone.

My program for my robot is progressing. Thanks to your help its coming along great. I've also found that I'm more and more able to solve my own problems with programming now.

One thing that I can't seem to solve:

I'm working on a part of my robot's human-socialization program in which she keeps track of the topic, and then adds her own input. For example, if I talk to my robot about Disneyland, she'll keep track of different aspects of the theme park. I do this with a variable, say for each park, and if one of the varibles is greater than 3, she'll say something like, "You seem to like Main Street a great deal." That part works more or less fine.

But when I first start up the program and mention a ride at Disneyland, such as "Rail Road" I get this exception:

<type'exceptions.AttributeError'>:'MyApp' object has no attribute 'topic' at line 1.

This is the code associated with the recognized speech "Rail Road":

if self.topic == "disneyland":
	speaker.Speak(random.choice(DisneyRideTrain))
else:
	speaker.Speak('Cool. What rail road did you ride')

I know what the exception means: it means that unless I say change the topic to "disneyland" this snippet won't work because the variable "self.topic" doesn't have anything associated with it. So what I need is a default, or startup, value for "self.topic."

As simple as it sounds, I don't know how that would work. I've tried adding code like:

Seagull One 0 Junior Poster in Training

In the python script for my robot, I'm searching for a way to detect a variable change. After doing a search, I found this example in VB.NET.

http://www.daniweb.com/forums/post610941.html#post610941

I've tried to translate it into a python bit, but with no success.

What I want my robot to do is this:

When talking to the robot, the robot ought to detect a change in topic. For instance, if I talk to my robot about, say Dinosaurs, and all of the sudden I say a string that has to do with another topic, have the robot say something like, "That's cool, but aren't we talking about Dinosaurs?"

Like so in this psuedo code:

class Topic:
    OnTopic = 'Dinosaurs'
    if OnTopic changes #Or tries to change? This is the main part I'm stumped on
        GetVariable(OnTopic)
        speaker.Speak('Thats cool, but arent we talking about', OnTopic)
        if "yes we are"
            speaker.Speak('Okay')
            Set OnTopic to 'Dinorsaurs'
        elif "No, now we're talking about movies"
            speaker.Speak('Okay, lets talk about movies')
            Set OnTopic to 'movies'

I'll continue to search for a solution myself. Thanks.

Seagull One 0 Junior Poster in Training

Thanks guys. I added the code snippet, tinkered around a bit, and it works great!

Seagull One 0 Junior Poster in Training

Okay, guys, its starting to work. One last thing I'm trying to fix for this issue: The moment I start my script my robot recites the three laws without me saying anything. At first the script wouldn't start up because it said (LOR1) was not defined, so I moved the class LawRecite further down the script and the then the program would run.

My robot recites the three laws on its own the first time I start the script, but after that its working like I want it to.

Is there a way the class can be adjusted so that my robot will not speak the three laws until I ask it?

By the way, I just want to say thanks to all of you on Daniweb in my quest to learn Python and programming. You guys are teaching me a lot!

Seagull One 0 Junior Poster in Training

Thanks, wooee, I added the snippet in. I've encountered a problem though:

after changing to 3 =
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\Nina Verbal Raw Input.py", line 135, in <module>
    print "after changing to 3 =",  LR.ThreeLaws
AttributeError: LawRecite instance has no attribute 'ThreeLaws'

Is the program searching for a definition for "ThreeLaws"?

Seagull One 0 Junior Poster in Training

Okay, I arranged it into a class, which I think I did right...

ThreeLaws = False

class LawRecite:
def Recite(self):
speaker.Speak(LOR1)
speaker.Speak(LOR2)
speaker.Speak(LOR3)
speaker.Speak(random.choice(LOR4))

LR = LawRecite()

Now if I ask my robot via speech recognition "Do you know the three laws of robotics?" it replies:

speaker.Speak ('Yes, I know them well. Would you like me to recite them for you?')
ThreeLaws = True

That part works fine. However, I've noticed that when I try to print if ThreeLaws is True, like so:

speaker.Speak ('Yes, I know them well. Would you like me to recite them for you?')
ThreeLaws = True
if ThreeLaws == True:
print 'Let's talk about the three laws of robotics'
else:
print 'Not right now'

I get an attribute error that says that 'NoneType' object has no attribute 'tb_lineno'.

Hmm...I think I understand what wooee meant by two blocks of memory with the same name. What I'm trying to do here is change the variable of ThreeLaws from True to False, but because I mention ThreeLaws = .... twice, that's causing it to be destroyed. Am I right? If so, what's the proper way to change a variable's value? Like a switch, I mean?

Seagull One 0 Junior Poster in Training

This problem has been bugging me for the past few days. I've tried all sorts of different things to get it to work, studied my books, but nothing.

It goes like this:
Let's say I want my robot to recite the three laws of robotics. I can say, "Recite the three laws of robotics," and the computer will recognize my speech and recite them perfectly via TTS. Now, let's say that this time I want to ask my robot if it knows the three laws? My robot will say "Yes, I know them well. Would you like me to recite them for you?"
Right after it says this a variable in the script called LawRecite changes to True. I know it is changing to True in my script because I have this code snipet:

speaker.Speak ('Yes, I know them well. Would you like me to recite them for you?')
LawRecite = True
if LawRecite == True:
print 'Lets talk about the three laws of Robotics'

and that string in the end is coming up, so I know nothing's wrong there.

The problem is, when I say "Yes please," which has this code snipet attatched to it:

while LawRecite == True:
speaker.Speak(LOR1)
speaker.Speak(LOR2)
speaker.Speak(LOR3)
speaker.Speak(random.choice(LOR4))
else:
speaker.Speak('Yes please what?')

my robot just keeps asking, "Yes please what?" as if the value to LawRecite is still False (or something else).

Logically, if the value for LawRecite is …

Seagull One 0 Junior Poster in Training

Well, I couldn't figure out what was wrong. I checked for speeling errors and anything else that might have been wrong but couldn't get anything. Since I'm building a robot and I mainly won't be using the script with a graphical user interface, I decided to use a simple solution:

Get rid of the code that involves a taskbar!

Hurray! I can talk to my robot again!

Thank you so much, Jeff! I couldn't do this without you. I'll continue to hit the books and brush up on my python.

Loren

Seagull One 0 Junior Poster in Training

Oh, I think I get it now. That's defined in

self.tbicon = wx.TaskBarIcon()
icon = wx.IconFromXPMData(getMondrianData())

I should've seen that coming.

I've added the wx to the other parts in that chunck of code, and thats seems to account for several more exceptions. Except for one of them (man, these exceptions are going on forever:confused:

Anyway, I'm now getting the wx-gui part of the script to appear, so we're getting pretty close.

What's troubling me this time is

wx.ACCEL_ALTEVT_TASKBAR_RIGHT_UP(self.tbicon, self.OnTaskBarMenu)

This error message comes up with it:

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\Nina Verbal Raw Input.py", line 674, in <module>
app = MyApp(0)
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7836, in __init__
self._BootstrapApp()
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7433, in _BootstrapApp
return _core_.PyApp__BootstrapApp(*args, **kwargs)
File "C:\Users\Loren\Desktop\My Robots\Nina Verbal Raw Input.py", line 565, in OnInit
self.SetUpTaskbar()
File "C:\Users\Loren\Desktop\My Robots\Nina Verbal Raw Input.py", line 546, in SetUpTaskbar
wx.ACCEL_ALTEVT_TASKBAR_RIGHT_UP(self.tbicon, self.OnTaskBarMenu)
AttributeError: 'module' object has no attribute 'ACCEL_ALTEVT_TASKBAR_RIGHT_UP'

Isn't the "(self.tbicon, self.OnTaskBarMenu)" the attribute of "wx.ACCEL_ALTEVT_TASKBAR_RIGHT_UP"?

Seagull One 0 Junior Poster in Training

Thanks Jeff!

I think we just have a little more ways to go. It's now giving me a NameError that goes like this:

Setting words - turned on
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\Nina Verbal Raw Input.py", line 674, in <module>
app = MyApp(0)
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7836, in __init__
self._BootstrapApp()
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7433, in _BootstrapApp
return _core_.PyApp__BootstrapApp(*args, **kwargs)
File "C:\Users\Loren\Desktop\My Robots\Nina Verbal Raw Input.py", line 565, in OnInit
self.SetUpTaskbar()
File "C:\Users\Loren\Desktop\My Robots\Nina Verbal Raw Input.py", line 545, in SetUpTaskbar
EVT_TASKBAR_LEFT_DCLICK(self.tbicon, self.OnTaskBarActivate)
NameError: global name 'EVT_TASKBAR_LEFT_DCLICK' is not defined

On this I'm clueless...but I'll see what I can find out about it.

Seagull One 0 Junior Poster in Training

Oh, right. Thanks, Jeff! That solved that problem.

Now when I run the script, the windows speed recognition activates! Theres another exception that comes up though, but since the windows speech recognition comes up just before the exception, I know we're getting close.

Here's whats coming up now:

Setting words - turned on
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\Nina Verbal Raw Input.py", line 674, in <module>
app = MyApp(0)
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7836, in __init__
self._BootstrapApp()
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7433, in _BootstrapApp
return _core_.PyApp__BootstrapApp(*args, **kwargs)
File "C:\Users\Loren\Desktop\My Robots\Nina Verbal Raw Input.py", line 553, in OnInit
self.frame = wx.Frame(NULL, -1, "Speech tester", wx.Point(10,10), wx.Size(770,300))
NameError: global name 'NULL' is not defined

Here's the chunk of code that seems to be affected.

def OnInit(self):
self.setItems()
self.InitSpeech()

self.frame = wx.Frame(NULL, -1, "Speech tester", wx.Point(10,10), wx.Size(770,300))
self.listBox = wx.ListBox(self.frame, self.LISTBOX_ID, wx.Point(10, 10), wx.Size(120, 200),
self.items.keys(), wx.LB_SINGLE)
self.addButton = wx.Button(self.frame, self.ADD_BUTTON_ID, "Add", wx.Point(10,230), wx.Size(50, 30))
self.deleteButton = wx.Button(self.frame, self.DELETE_BUTTON_ID, "Delete", wx.Point(80, 230), wx.Size(50, 30))
self.editor = wx.TextCtrl(self.frame, self.EDITOR_ID, "", wx.Point(140,10), wx.Size(600,200),
style=wx.SUNKEN_BORDER+wx.TE_MULTILINE+wx.TE_PROCESS_TAB)
self.testButton = wx.Button(self.frame, self.TEST_BUTTON_ID, "Test", wx.Point(140, 230), wx.Size(50, 30))

self.turnonButton = wx.Button(self.frame, self.TURNON_BUTTON_ID, "On", wx.Point(210, 230), wx.Size(50, 30))
self.turnoffButton = wx.Button(self.frame, self.TURNOFF_BUTTON_ID, "Off", wx.Point(280, 230), wx.Size(50, 30))

self.SetUpTaskbar()

EVT_LISTBOX(self, self.LISTBOX_ID, self.OnListBoxSelect)
EVT_BUTTON(self, self.ADD_BUTTON_ID, self.OnAddClick)

Seagull One 0 Junior Poster in Training

Hi Jeff. I think my problem was I hadn't used the MakePy Windows speech Object Library on it, because it got rid of that error. Now I'm getting something else, much farther down 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\Nina Verbal Raw Input.py", line 674, in <module>
app = MyApp(0)
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7836, in __init__
self._BootstrapApp()
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wx\_core.py", line 7433, in _BootstrapApp
return _core_.PyApp__BootstrapApp(*args, **kwargs)
File "C:\Users\Loren\Desktop\My Robots\Nina Verbal Raw Input.py", line 551, in OnInit
self.InitSpeech()
File "C:\Users\Loren\Desktop\My Robots\Nina Verbal Raw Input.py", line 527, in InitSpeech
self.turnedOn = true
NameError: global name 'true' is not defined

From what I understand, 'true' is a type of switch or property. It should work in any python script without importing or fancy defining or anything like that.

Here's the chunk of code that seems to be affected:

def InitSpeech(self):
listener = win32com.client.Dispatch("SAPI.SpSharedRecognizer")
self.context = listener.CreateRecoContext()
self.grammar = self.context.CreateGrammar()
self.grammar.DictationSetState(0)
self.ListItemsRule = self.grammar.Rules.Add("ListItemsRule", constants.SRATopLevel + constants.SRADynamic, 0)
events = ContextEvents(self.context)
self.turnedOn = true
self.SetWords()

Its part of a class called "MyApp(wx.App):" which is extremely vast with the lists of phrases my robot responds to.

Any ideas? I think we're both sort of exploring this speech recognition python territory. I'll keep investigating on my own …

Seagull One 0 Junior Poster in Training

I believe the bug is indeed, in speaker.Speak(). I tried retyping the script in the comman line to see step by step what was working and what was going through. The moment I finished typing in

class ContextEvents(win32com.client.getevents("SAPI.SpSharedRecoContext")):
def OnRecognition(self, StreamNumber, StreamPosition, RecognitionType, Result):
newResult = win32com.client.Dispatch(Result)

I got that

TypeError: Error when calling the metaclass bases

I only have a rough idea of whats happening in the computer as far as coding is concerned, so I'm not sure how to fix this problem...

Seagull One 0 Junior Poster in Training

Okay, I think I found the answer to that. All I had to do was change, say wxbitmap to wx.bitmap, in my script.

But now I'm getting something else. When I try running the script, I get this error message:

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\Nina Verbal Raw Input.py", line 75, in <module>
class ContextEvents(win32com.client.getevents("SAPI.SpSharedRecoContext")):
TypeError: Error when calling the metaclass bases
cannot create 'NoneType' instances

I first thought this had something to do with the SAPI SDK 5.1 not being install on my New computer (my old laptop suffered a spill, so that's why I'm having trouble getting this script to work again on my new one). But apparently, after reinstalling it, I get the same message. Could it be that the python win32 extention isn't installed on my laptop? Because I thought I installed it...

Seagull One 0 Junior Poster in Training

Hello again, Jeff!

I test the wxPython install like you said and got the result as you indicated, so its no wxPython.

I think I've isolated the problem to somewhere much earlier in my program:

from wxPython.wx import *

I tried typing this in the command prompt and it gave back this result:

from wxPython.wx import *
__main__:1: DeprecationWarning: The wxPython compatibility package is no longer automatically generated or actively maintained. Please switch to the wx package as soon as possible.
Traceback (most recent call last):
File "<interactive input>", line 1, in <module>
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wxPython\__init__.py", line 15, in <module>
import _wx
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wxPython\_wx.py", line 8, in <module>
from _misc import *
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wxPython\_misc.py", line 456, in <module>
wxDateTime_GetNumberOfDaysinYear = wx._misc.DateTime_GetNumberOfDaysinYear
AttributeError: 'module' object has no attribute 'DateTime_GetNumberOfDaysinYear'

If I understand correctly, the package I just installed isn't good anymore, so I need to switch to the "wx" package? Where can I find that?

Seagull One 0 Junior Poster in Training

Hello everyone! I haven't programmed in quite a while and now that I'm getting back into the programming environment for my robotics project again, I'm a little stumped on something:

I'm getting this error message for an exception raised in my VAST python script for my robot. It goes like this:

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\Nina Verbal Raw Input.py", line 12, in <module>
from wxPython.wx import *
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wxPython\__init__.py", line 15, in <module>
import _wx
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wxPython\_wx.py", line 8, in <module>
from _misc import *
File "C:\Python25\lib\site-packages\wx-2.8-msw-unicode\wxPython\_misc.py", line 456, in <module>
wxDateTime_GetNumberOfDaysinYear = wx._misc.DateTime_GetNumberOfDaysinYear
AttributeError: 'module' object has no attribute 'DateTime_GetNumberOfDaysinYear'

What stumps me is when I go to line 456, I only see this:

"I'll get over it" : "speaker.Speak(random.choice(Health2))",

I went back to Health2, but didn't see anything on DateTime_GetNumberOfDaysinYear, there. I even did a find for the phrase in my scripts, but it says it can't find it. I brushed up on my python books, but can't isolate the problem.

If someone could give me any help with this, I'd be obliged. Thanks in advance.

Seagull One 0 Junior Poster in Training

Sorry I haven't replied in a while: been busy.

Ah, ha! So for verbal raw_input, I would use a GetText() somewhere in my script! Okay, so what I have to do is implement that operation.

But I wonder if I would have to implement a database of names for the computer to recognize, or is this there a way to make the computer listen and get text from anything you say? (I'm skeptical of the latter...).

Seagull One 0 Junior Poster in Training

Okay, Jeff. I implemented "return 'Hello Nina'" as you suggested and got lots of good stuff!

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 588, in _
ivokeex_
   return func<*args>
  File "C:\Users\Owner\Desktop\Python Script\Nina Verbal Raw Input.py", line 86,
 in On Recognition
    "for text ' "+newResult.PhraseInfo.GetText<>+"'">
<type 'exceptions.AttributeError'>: 'NoneType' object has no attribute 'tb_linen
o'

Its pretty much greek to me, but let me see if I can decipher it.

The first part is pretty self explanatory: it uses pythoncom.
Then it gives me a directory, so it must be using something called "policy.py" in there as well. It gives me the same directory for several indicated lines three times over.
Then apparently it lists one of the lines I recognize in Inigo's original code "newResult.PhraseInfo.GetText"

Okay, now I just have to take this stuff and make it work for me somehow. Okay, I've never done this before, so if you could direct me a little, maybe?:?: