我正在尝试为我正在编码的AI使用SpeechRecognition STT模块,我也正在使用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())
如果有人可以解释和解决我的问题,那将是有帮助的
谢谢!
最佳答案
点击此链接。
它具有与python 3兼容的所有更新。
https://github.com/jpercent/pyttsx