使用pyttsx的python文本到语音

使用pyttsx的python文本到语音,python,raspberry-pi,pyttsx,Python,Raspberry Pi,Pyttsx,我想用我的树莓圆周率来宣布一些文字。我已经安装了pyttsx,但无法使用它。我正在使用python2.7 我的节目: import pyttsx engine= pyttsx.init() engine.setProperty('rate',70) voices=engine.getProperty('voices') for voice in voices: print "Using voice:", repr(voice) engine.setProperty('voice'

我想用我的树莓圆周率来宣布一些文字。我已经安装了pyttsx,但无法使用它。我正在使用python2.7

我的节目:

import pyttsx
engine= pyttsx.init()
engine.setProperty('rate',70)
voices=engine.getProperty('voices')
for voice in voices:
    print "Using voice:", repr(voice)
    engine.setProperty('voice',voice.id)
    engine.say("Hello Hello Hello")
engine.runAndWait()
但我得到了这个错误:

Traceback (most recent call last):
File "/home/pi/announce.py", line 2, in <module>
engine= pyttsx.init()
File "/usr/local/lib/python2.7/dist-packages/pyttsx-1.1-     py2.7.egg/pyttsx/__init__.py", line 39, in init
eng = Engine(driverName, debug)
File "/usr/local/lib/python2.7/dist-packages/pyttsx-1.1- py2.7.egg/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-1.1-p   y2.7.egg/pyttsx/driver.py", line 64, in __init__
  self._module = __import__(name, globals(), locals(), [driverName])
  File "/usr/local/lib/python2.7/dist-packages/pyttsx-1.1-py2.7.egg/pyttsx/drivers/espeak.py", line 19, in <module>
   import _espeak
   File "/usr/local/lib/python2.7/dist-packages/pyttsx-1.1-py2.7.egg/pyttsx/drivers/_espeak.py", line 24, in <module>
   dll = cdll.LoadLibrary('libespeak.so.1')
   File "/usr/lib/python2.7/ctypes/__init__.py", line 443, in LoadLibrary
    return self._dlltype(name)
   File "/usr/lib/python2.7/ctypes/__init__.py", line 365, in __init__
   self._handle = _dlopen(self._name, mode)
OSError: libespeak.so.1: cannot open shared object file: No such file or directory
回溯(最近一次呼叫最后一次):
文件“/home/pi/announce.py”,第2行,在
engine=pyttsx.init()
文件“/usr/local/lib/python2.7/dist packages/pyttsx-1.1-py2.7.egg/pyttsx/_init__.py”,第39行,在init中
eng=引擎(驱动器名称,调试)
文件“/usr/local/lib/python2.7/dist packages/pyttsx-1.1-py2.7.egg/pyttsx/engine.py”,第45行,在__
self.proxy=driver.DriverProxy(weakref.proxy(self)、driverName、debug)
文件“/usr/local/lib/python2.7/dist-packages/pyttsx-1.1-p y2.7.egg/pyttsx/driver.py”,第64行,在__
self.\u模块=\uuuuu导入\uuuuu(名称、全局变量()、局部变量()、[driverName])
文件“/usr/local/lib/python2.7/dist packages/pyttsx-1.1-py2.7.egg/pyttsx/drivers/espeak.py”,第19行,in
导入espeak
文件“/usr/local/lib/python2.7/dist packages/pyttsx-1.1-py2.7.egg/pyttsx/drivers/_espeak.py”,第24行,in
dll=cdll.LoadLibrary('libespeak.so.1')
LoadLibrary中的文件“/usr/lib/python2.7/ctypes/_init__uuu.py”,第443行
返回自我类型(名称)
文件“/usr/lib/python2.7/ctypes/_init__.py”,第365行,在_init中__
self.\u handle=\u dlopen(self.\u名称,模式)
OSError:libespeak.so.1:无法打开共享对象文件:没有这样的文件或目录

这是因为您的系统上没有安装
espeak
。 这就是它给出错误的原因

libespeak.so.1错误:未找到此类文件或目录

尝试使用以下方法安装espeak:

sudo apt-get update && sudo apt-get install espeak

如果你使用的是Ubuntu,请使用这个

sudo apt install libespeak1
试试这个:: 在Ubuntu/Linux终端上运行

1.
pip安装pyttsx3

2.
sudo apt安装libespeak1


您必须已成功安装。

您还必须安装linux软件包
python-espeak
。(
sudo-apt-get-install-python-espeak
)谢谢您,先生。现在工作正常@sebastian stigler