Python错误:没有名为' engine'

时间:2017-01-25 03:05:51

标签: python module pyttsx

我正在尝试将SpeechRecognition STT模块用于我正在编码的AI,并且我也使用Pyttsx但是我得到了这个错误。

 File "/Library/Frameworks/Python.framework/Versions/3.5/lib/python3.5/site-packages/pyttsx/__init__.py", line 18, in <module>
 from engine import Engine
 ImportError: No module named 'engine'

很多人都试图回答这个问题,因为所有有这个问题的人都没有解释或不能解决问题!

这是我的代码

import speech_recognition
import pyttsx

speech_engine = pyttsx.init('sapi5') # see     http://pyttsx.readthedocs.org/en/latest/engine.html#pyttsx.init
speech_engine.setProperty('rate', 150)

def speak(text):
    speech_engine.say(text)
    speech_engine.runAndWait()

recognizer = speech_recognition.Recognizer()

def listen():
    with speech_recognition.Microphone() as source:
        recognizer.adjust_for_ambient_noise(source)
        audio = recognizer.listen(source)

    try:
        return recognizer.recognize_sphinx(audio) 
        # or: return recognizer.recognize_google(audio)
    except speech_recognition.UnknownValueError:
        print("Could not understand audio")
    except speech_recognition.RequestError as e:
        print("Recog Error; {0}".format(e))

    return ""



speak("Say something!")
speak("I heard you say " + listen())

如果有人可以解释并解决我的问题会有所帮助 谢谢!

1 个答案:

答案 0 :(得分:1)

请点击此链接。 它具有与python 3兼容的所有更新。 https://github.com/jpercent/pyttsx