pyttsx: No module named 'engine'

前端 未结 7 1287
青春惊慌失措
青春惊慌失措 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:39

    I found out the solution. Library was created in python2 language and there are not a lot of differences between those 2 versions, but exclusively in this case that occurs.

    Move to your DP folder and change in engine.py "except Exception as e" instead of "except Exception, e", line 67. Do the same in drive.py, line 105.

    Because of files are secured try to execute, e. g.

    sudo nano engine.py (or drive.py)

    I guess I helped everyone with that kind of problem. :)

    0 讨论(0)
  • 2020-12-03 01:43

    For Python3, please install the latest version via pip3 install pyttsx3 and call import pyttsx3.

    0 讨论(0)
  • 2020-12-03 01:49

    Modify site_packages/pyttsx/init.py "from engine import Engine" to

    from .engine import Engine
    

    Modify site_packages/pyttsx/engine.py "import driver" to

    from . import driver
    

    Reason: The import statement "from engine import Engine" tells python to import Engine module from directory engine. In our case engine is not a directory, it's a python file, engine.py. So we need to tell python to import this engine module from current directory (".").

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2020-12-03 01:57

    Guys there is an updated package compatible with Python3 :

    pyttsx3

    Works offline with no delay in the sound produced.

    Installation:

    pip install pyttsx3
    

    Visit https://pyttsx3.readthedocs.io for the full usage docs. Thanks!

    0 讨论(0)
  • 2020-12-03 01:59

    Combining the advice from Jacob Tsui and Jokhongir Mamarasulov worked for me. To summarize:

    In site_packages/pyttsx/init.py, modify "from engine import Engine" to

    from .engine import Engine
    

    Then, in site_packages/pyttsx/engine.py,

    1. Modify import driver to

      from . import driver
      
    2. Modify except Exception, e to

      except Exception as e
      

    And finally, in site_packages/pyttsx/driver.py modify except Exception, e to

    except Exception as e
    

    See the responses from the aforementioned authors for the rationale behind these changes.

    0 讨论(0)
提交回复
热议问题