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

2024-04-16 14:30:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我想用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

Tags: inpyselfvenvinitlibpackagesline