pyttsx pyttsx.init() not working

ぃ、小莉子 提交于 2021-02-07 17:57:36

问题


So I am making a Chatbot/Virtual assistant with Python, I was searching for a text-to-speech engine for Python and found pyttsx. I downloaded it with pip (like this: sudo pip install pyttsx ) (btw I am using Linux). I am using Python 2.7 (I tried with python 3.5 gave me the same error). I imported it and it worked but when I put (as this tutorial "told me" to https://pythonspot.com/en/speech-engines-with-python-tutorial/) engine = pyttsx.init().

The code looks like this:

import pyttsx
engine = pyttsx.init()
engine.say('Hello There')
engine.runAndWait()

And this is the error I am getting:

    Traceback (most recent call last):
  File "/home/theshoutingparrot/Desktop/Programming/Python/Bots/A.I/speechtotext.py", line 2, in <module>
    engine = pyttsx.init()
  File "/usr/local/lib/python2.7/dist-packages/pyttsx/__init__.py", line 39, in init
    eng = Engine(driverName, debug)
  File "/usr/local/lib/python2.7/dist-packages/pyttsx/engine.py", line 45, in __init__
    self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
  File "/usr/local/lib/python2.7/dist-packages/pyttsx/driver.py", line 64, in __init__
    self._module = __import__(name, globals(), locals(), [driverName])
  File "/usr/local/lib/python2.7/dist-packages/pyttsx/drivers/espeak.py", line 19, in <module>
    import _espeak
  File "/usr/local/lib/python2.7/dist-packages/pyttsx/drivers/_espeak.py", line 24, in <module>
    dll = cdll.LoadLibrary('libespeak.so.1')
  File "/usr/lib/python2.7/ctypes/__init__.py", line 440, in LoadLibrary
    return self._dlltype(name)
  File "/usr/lib/python2.7/ctypes/__init__.py", line 362, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: libespeak.so.1: cannot open shared object file: No such file or directory

Any help would be good, or suggest a nother txt-to-speech engine Thx in advance if you can help.


回答1:


You have to install espeak 1st:

sudo apt-get install espeak



回答2:


I am working in windows 7, I got the importerror at end when doing the same & engine = pyttsx.init() wasn't working before. I installed pypiwin32 to resolve the importerror for win32com.client. Hope it works for you.




回答3:


Do this:

import pyttsx

engine = pyttsx.init(espeak) # "espeak" defines what engine program is running on
engine.say("Hello There")
engine.runAndWait()

Hope this helped!




回答4:


I had same in Ubuntu 18.04

Install

sudo apt-get install espeak

Check it :

espeak --stdout "this is a test" | paplay

and run the following code

import pyttsx
engine = pyttsx.init() 
engine.say("Hello There")
engine.runAndWait()


来源:https://stackoverflow.com/questions/44890310/pyttsx-pyttsx-init-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!