Ejemplo n.º 1
0
def callback(phr):
    if phr == '停止交互':
        speech.say("Goodbye. 人机交互即将关闭,谢谢使用")
        speech.stoplistening()
        sys.exit()
    elif phr == '好累啊':
        webbrowser.open_new("http://www.youku.com/")
    elif phr == '深度学习':
        speech.say("深度学习是个好东西,语音识别已经有了")
    elif phr == 'cmd':
        speech.say("即将打开CMD")
        os.popen("C:\Windows\System32\cmd.exe")
Ejemplo n.º 2
0
# If you don't have a specific set of phrases in mind, listenforanything() will
# run a callback every time anything is heard that doesn't match another Listener.
def L3callback(phrase, listener):
  speech.say(phrase) # repeat it back
  if phrase == "stop now please":
    # The listener returned by listenfor() and listenforanything()
    # is also passed to the callback.
    listener.stoplistening()
listener3 = speech.listenforanything(L3callback)

# All callbacks get automatically executed on a single separate thread.
# Meanwhile, you can just do whatever with your program, or sleep.
# As long as your main program is running code, Listeners will keep listening.

import time
while listener3.islistening(): # till "stop now please" is heard
  time.sleep(1)

assert speech.islistening() # to at least one thing
print ("Dictation is now stopped.  listeners 1 and 2 are still going.")

listener1.stoplistening()
print ("Now only listener 2 is going")

# Listen with listener2 for a while more, then turn it off.
time.sleep(30)

speech.stoplistening() # stop all remaining listeners
assert not speech.islistening()
Ejemplo n.º 3
0
# As long as your main program is running code, Listeners will keep listening.

import time
while listener3.islistening(): # till "stop now please" is heard
  time.sleep(1)

assert speech.islistening() # to at least one thing
print "Dictation is now stopped.  listeners 1 and 2 are still going."

listener1.stoplistening()
print "Now only listener 2 is going"

# Listen with listener2 for a while more, then turn it off.
time.sleep(30)

speech.stoplistening() # stop all remaining listeners
assert not speech.islistening()


# obtain audio from the microphone
r = sr.Recognizer()
with sr.Microphone() as source:
    print("Say something!")
    audio = r.listen(source)

try:
    print("AT&T Speech to Text thinks you said " + r.recognize_att(audio, app_key=ATT_APP_KEY, app_secret=ATT_APP_SECRET))
except sr.UnknownValueError:
    print("AT&T Speech to Text could not understand audio")
except sr.RequestError as e:
    print("Could not request results from AT&T Speech to Text service; {0}".format(e))
Ejemplo n.º 4
0
	def sayit(self):
		speech.stoplistening()
		speech.say(self.inst)
Ejemplo n.º 5
0
 def __stop__(self):
     speech.stoplistening()
Ejemplo n.º 6
0
      if hrdel<0: hrdel+=24
      if mndel<0: mndel+=60
      if scdel<0: scdel+=60
      delay = 3600*hrdel + 60*mndel + scdel
    print delay
    #Create a thread to execute action at given time
    Timer(delay, tmp).start()

while True:

    try:
        print "Please say the command out loud or press Ctrl+C twice to exit"
        speech.say("Please say the command out loud")
        input = speech.input("Please press Control plus C to type the command instead.") #"on fan zero nine three eight"
        print input,
        while speech.islistening():
            delta = speech.input(" - ")
            input += delta
            print delta,
        speech.say("You said: "+input)
        print ""
    except KeyboardInterrupt:
        speech.stoplistening()
        print ("Please type your command here; Press Ctrl+C to exit")
        try: input = raw_input()
        except KeyboardInterrupt: break

    if input!="": evaluate(input)
    input = ""