4

所以我正在用 Python 做一个聊天机器人/虚拟助手,我正在寻找 Python 的文本到语音引擎并找到了 pyttsx。我用 pip 下载了它(像这样:sudo pip install pyttsx )(顺便说一句,我使用的是Linux)。我正在使用 Python 2.7(我尝试使用 python 3.5 给了我同样的错误)。我导入了它并且它起作用了,但是当我把它(本教程“告诉我”到https://pythonspot.com/en/speech-engines-with-python-tutorial/)时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

任何帮助都会很好,或者如果您可以提供帮助,请提前建议另一个 txt-to-speech 引擎 Thx。

4

4 回答 4

4

您必须安装 espeak 1st:

sudo apt-get install espeak
于 2017-08-21T19:34:07.080 回答
3

我在 Windows 7 中工作,在执行相同操作时最后出现 importerror,并且 engine = pyttsx.init() 之前没有工作。我安装了pypiwin32来解决win32com.client的 importerror 。希望对你有效。

于 2017-07-21T16:36:43.490 回答
3

我在 Ubuntu 18.04 中也有同样的情况

安装

sudo apt-get install espeak

核实 :

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

并运行以下代码

import pyttsx
engine = pyttsx.init() 
engine.say("Hello There")
engine.runAndWait()
于 2018-11-10T09:07:03.283 回答
2

做这个:

import pyttsx

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

希望这有帮助!

于 2017-08-28T22:38:13.953 回答