简体   繁体   中英

Python error: No module named 'engine'

I am trying to use the SpeechRecognition STT module for an AI i am coding and i'm also using Pyttsx but i get this error.

 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'

Alot of people have tried to answer this problem, for all the people having this problem but the answers aren't explained or don't work!

Here's my code

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())

if someone can explain and fix my problem that would be helpful thank you!

Follow this link. It has all the updates compatible with python 3. https://github.com/jpercent/pyttsx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM