pyttsx: No module named 'engine'

前端 未结 7 1309
青春惊慌失措
青春惊慌失措 2020-12-03 01:02

I\'m trying to install TTS package by using this. Everything was okay until I tried to execute the following command:

import pyttsx

I got b

7条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-03 01:54

    I just had the same problem, try using pyttsx3 instead of pyttsx First install pyttsx3

    pip install pyttsx3
    

    and change the

    import pyttsx
    

    for

    import pyttsx3
    

    After that you have to change engine import (if you're using it in your main .py file). Use engineio instead. Install it

    pip install python-engineio
    

    then change import engine for import engineio and change your variables.

    Here's an example

    import pyttsx3
    # import engineio #engineio module is not needed.
    
    engineio = pyttsx3.init()
    voices = engineio.getProperty('voices')
    engineio.setProperty('rate', 130)    # Aquí puedes seleccionar la velocidad de la voz
    engineio.setProperty('voice',voices[0].id)
    
    def speak(text):
        engineio.say(text)
        engineio.runAndWait()
    
    speak("What do you want me to say?")
    while(1):
        phrase = input("--> ")
        if (phrase == "exit"):
            exit(0)
        speak(phrase)
        print(voices)
    

    Hope this helps someone

提交回复
热议问题