为什么启动pyttsx3引擎时出现错误?

时间:2019-09-24 15:34:34

标签: python python-3.x text-to-speech pyttsx

我想使用pyttsx3(当然是python)制作语音助手。使用.init()函数时出现多个错误。

import os
import time
import speech_recognition as sr
import pyttsx3


def talk(text):
    engine = pyttsx3.init()
    engine.say(text)
    engine.runAndWait()

talk("Hello")

这些是我得到的错误...

>Traceback (most recent call last):
  File "/Users/tldr/PycharmProjects/voiceAssistantProject/venv/lib/python3.7/site-packages/pyttsx3/__init__.py", line 20, in init
    eng = _activeEngines[driverName]
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/weakref.py", line 137, in __getitem__
    o = self.data[key]()
KeyError: None

>During handling of the above exception, another exception occurred:

>Traceback (most recent call last):
  File "/Users/tldr/PycharmProjects/voiceAssistantProject/voice_assistant1.py", line 12, in <module>
    talk("Hello")
  File "/Users/tldr/PycharmProjects/voiceAssistantProject/voice_assistant1.py", line 8, in talk
    engine = pyttsx3.init()
  File "/Users/tldr/PycharmProjects/voiceAssistantProject/venv/lib/python3.7/site-packages/pyttsx3/__init__.py", line 22, in init
    eng = Engine(driverName, debug)
  File "/Users/tldr/PycharmProjects/voiceAssistantProject/venv/lib/python3.7/site-packages/pyttsx3/engine.py", line 30, in __init__
    self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
  File "/Users/tldr/PycharmProjects/voiceAssistantProject/venv/lib/python3.7/site-packages/pyttsx3/driver.py", line 52, in __init__
    self._driver = self._module.buildDriver(weakref.proxy(self))
  File "/Users/tldr/PycharmProjects/voiceAssistantProject/venv/lib/python3.7/site-packages/pyttsx3/drivers/nsss.py", line 9, in buildDriver
    return NSSpeechDriver.alloc().initWithProxy(proxy)
  File "/Users/tldr/PycharmProjects/voiceAssistantProject/venv/lib/python3.7/site-packages/pyttsx3/drivers/nsss.py", line 19, in initWithProxy
    self._tts.setDelegate_(self)
AttributeError: 'NoneType' object has no attribute 'setDelegate_'

>Process finished with exit code 1

0 个答案:

没有答案