python文本到语音使用pyttsx [英] python text to speech using pyttsx

查看:57
本文介绍了python文本到语音使用pyttsx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用我的树莓派宣布一些文字.我已经安装了 pyttsx 但无法使用它.我使用的是 python2.7

I want to use my raspberry pi to announce some text. i have installed pyttsx but not able to use it.i am using 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

推荐答案

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

It's because you don't have espeak installed on your system. That's why it is giving error

libespeak.so.1 错误:找不到这样的文件或目录.

libespeak.so.1 error: no such file or directory found.

尝试使用以下命令安装 espeak:

Try to install espeak using:

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

这篇关于python文本到语音使用pyttsx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆