python pyttsx pyttsx.init()不工作

t3psigkw  于 2023-01-04  发布在  Python
关注(0)|答案(4)|浏览(142)

所以我用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

任何帮助都是好的,或者如果你能帮忙的话,提前建议一个其他的文本到语音引擎。

mpgws1up

mpgws1up1#

您必须安装espeak 1st:

sudo apt-get install espeak
k0pti3hp

k0pti3hp2#

我在windows 7下工作,我在做同样的操作时得到了输入错误。init()以前不工作。我安装了pypiwin32来解决 win32com.client 的输入错误。希望它对你有用。

zaq34kh6

zaq34kh63#

我在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()
3hvapo4f

3hvapo4f4#

请执行以下操作:

import pyttsx

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

希望这有帮助!

相关问题