【问题标题】:pyttsx pyttsx.init() not workingpyttsx pyttsx.init() 不工作
【发布时间】:2017-12-07 00:03:09
【问题描述】:

所以我正在用 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 引擎 如果您能提供帮助,请提前谢谢。

【问题讨论】:

    标签: python text-to-speech pyttsx


    【解决方案1】:

    你必须安装 espeak 1st:

    sudo apt-get install espeak
    

    【讨论】:

      【解决方案2】:

      我在 Windows 7 中工作,在执行相同操作时最后出现 importerror,并且 engine = pyttsx.init() 之前无法正常工作。我安装了 pypiwin32 来解决 win32com.client 的导入错误。 希望它对你有用。

      【讨论】:

        【解决方案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()
        

        【讨论】:

          【解决方案4】:

          这样做:

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

          希望这有帮助!

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2020-09-07
            • 1970-01-01
            • 2021-01-18
            • 1970-01-01
            • 2016-07-19
            • 1970-01-01
            • 2020-02-16
            相关资源
            最近更新 更多