Python pyttsx pyttsx.init()不工作

Python pyttsx pyttsx.init()不工作,python,text-to-speech,pyttsx,Python,Text To Speech,Pyttsx,所以我用Python制作了一个聊天机器人/虚拟助手 搜索Python的文本到语音引擎并找到pyttsx。 我用pip下载了它(如下:sudopip安装pyttsx )(顺便说一句,我使用的是Linux)。我使用的是Python2.7(我尝试使用Python3.5时也出现了同样的错误)。 我导入了它,它工作了,但是当我将(正如本教程“告诉我的”)engine=pyttsx.init()放入时 代码如下所示: import pyttsx engine = pyttsx.init() engine.s

所以我用Python制作了一个聊天机器人/虚拟助手 搜索Python的文本到语音引擎并找到pyttsx。 我用pip下载了它(如下:
sudopip安装pyttsx
)(顺便说一句,我使用的是Linux)。我使用的是Python2.7(我尝试使用Python3.5时也出现了同样的错误)。 我导入了它,它工作了,但是当我将(正如本教程“告诉我的”)engine=pyttsx.init()放入

代码如下所示:

import pyttsx
engine = pyttsx.init()
engine.say('Hello There')
engine.runAndWait()
这就是我得到的错误:

    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
回溯(最近一次呼叫最后一次):
文件“/home/theshoutingparrot/Desktop/Programming/Python/Bots/A.I/speechtotext.py”,第2行,在
engine=pyttsx.init()
文件“/usr/local/lib/python2.7/dist packages/pyttsx/_init__.py”,第39行,在init中
eng=引擎(驱动器名称,调试)
文件“/usr/local/lib/python2.7/dist packages/pyttsx/engine.py”,第45行,在__
self.proxy=driver.DriverProxy(weakref.proxy(self)、driverName、debug)
文件“/usr/local/lib/python2.7/dist-packages/pyttsx/driver.py”,第64行,在__
self.\u模块=\uuuuu导入\uuuuu(名称、全局变量()、局部变量()、[driverName])
文件“/usr/local/lib/python2.7/dist-packages/pyttsx/drivers/espeak.py”,第19行,在
导入espeak
文件“/usr/local/lib/python2.7/dist-packages/pyttsx/drivers/_-espeak.py”,第24行,在
dll=cdll.LoadLibrary('libespeak.so.1')
LoadLibrary中第440行的文件“/usr/lib/python2.7/ctypes/_init__uuu.py”
返回自我类型(名称)
文件“/usr/lib/python2.7/ctypes/_init__.py”,第362行,在_init中__
self.\u handle=\u dlopen(self.\u名称,模式)
OSError:libespeak.so.1:无法打开共享对象文件:没有这样的文件或目录
任何帮助都很好,或者建议另一个txt到语音引擎
如果您能提供帮助,请提前发送Thx。

我在windows 7中工作,在执行相同操作时,我最终收到了importerror&engine=pyttsx.init()以前不工作。我安装了pypiwin32来解决win32com.client的导入问题。
希望它对您有用。

您必须先安装espeak:

sudo apt-get install espeak
这样做:

import pyttsx

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

希望这有帮助

我在Ubuntu18.04中也有过同样的经历

安装

sudo apt-get install espeak
检查它:

espeak --stdout "this is a test" | paplay
并运行以下代码

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