Sunday, October 27, 2013

Speech driven machines: Pretty easy these days

How do you make your machines respond to your verbal commands? Turn the lights on and off? Switch the appliances on and off? Query for the weather? Query for how many messages you have? No problem given modern machinery.

from pygsr import Pygsr
import os
import urllib2
speech = Pygsr()
while 1==1:
        speech.record(3) #Waiting for someone to call upon the machine
        try:
                phrase, complete_response = speech.speech_to_text('en_US') 
        except urllib2.HTTPError:
                print "No match"
                continue
        if "machine" in phrase:
                os.system('espeak  -s 155 -a 200 "I am at your command." ' ) #Prompt for the command
                speech.record(3)
                try:
                        phrase, complete_response = speech.speech_to_text('en_US')
                except urllib2.HTTPError:
                        os.system('espeak  -s 155 -a 200 "I did not understand." ' )
                if ("do" in phrase) and ("something" in phrase):
                        os.system('espeak  -s 155 -a 200 "I am doing something." ' ) #Do something
                elif ("end" in phrase) or ("exit" in phrase):
                        os.system('espeak  -s 155 -a 200 "Ending program." ' )
                        break
                else:
                        os.system('espeak  -s 155 -a 200 "Unknown command." ' )

No comments:

Post a Comment