Python中的语音识别语法错误

Python中的语音识别语法错误,python,syntax-error,speech-recognition,Python,Syntax Error,Speech Recognition,我正在尝试运行此程序,但每次尝试运行时,都会出现语法错误,下面是我在终端中遇到的错误图片: 以下是我正在使用的代码: Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03) [GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin Type "copyright", "credits" or "license()" for more information. >>>

我正在尝试运行此程序,但每次尝试运行时,都会出现语法错误,下面是我在终端中遇到的错误图片: 以下是我正在使用的代码:

Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> WARNING: The version of Tcl/Tk (8.5.9) in use may be unstable.
Visit http://www.python.org/download/mac/tcltk/ for current information.
import speech_recognition as sr
import pyttsx


engine = pyttsx.init()
engine.setProperty('rate', 70)
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[10].id)

r = sr.Recognizer()
m = sr.Microphone()

try:
    print("A moment of silence, please...")
    with m as source: r.adjust_for_ambient_noise(source)
    print("Set minimum energy threshold to {}".format(r.energy_threshold))
    while True:
        print("Say something!")
        with m as source: audio = r.listen(source)
        print("Got it! Now to recognize it...")
        try:
            # recognize speech using Google Speech Recognition
            value = r.recognize_google(audio)

            # we need some special handling here to correctly print unicode characters to standard output
            if str is bytes: # this version of Python uses bytes for strings (Python 2)
                print(u"You said {}".format(value).encode("utf-8"))
                engine.say('How are you today?')
                engine.runAndWait()
            else: # this version of Python uses unicode for strings (Python 3+)
                print("You said {}".format(value))
        except sr.UnknownValueError:
            print("Oops! Didn't catch that")
        except sr.RequestError as e:
            print("Uh oh! Couldn't request results from Google Speech Recognition service; {0}".format(e))

except KeyboardInterrupt:
    pass

删除此部分或将其注释掉:

Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 23 2015, 02:52:03) 
[GCC 4.2.1 (Apple Inc. build 5666) (dot 3)] on darwin
Type "copyright", "credits" or "license()" for more information.
>>> WARNING: The version of Tcl/Tk (8.5.9) in use may be unstable.
Visit http://www.python.org/download/mac/tcltk/ for current information.

我不知道您是从哪里复制的,但是
Python 3.4.3(v3.4.3:9b73f1c3e601,2015年2月23日,02:52:03)
是无效的代码。嘿,我删除了第一部分,现在我收到了错误消息:
文件“speechrecognition.py”,第1行,在导入语音识别为sr ImportError时:没有名为speech_recognition的模块
您是否确保语音识别确实存在?