python - 我在运行一个简单的 pyttsx3 示例时遇到错误

标签 python python-3.x python-2.7 audio pyttsx

在 windows 和 rasbian 中分别使用 python 3.8 和 2.7 的 pyttsx3 的困难

当我试图运行一个简单的基本 pyttsx3 代码出错,请建议更换此软件包。我正在尝试开发个人助理,我需要 pyttsx3 模块才能工作。关于 的所有教程pyttsx3 它可以正常工作,没有任何错误,但使用 python 3.8 它会出错。我尝试在 Windows 和 raspbian 中使用这个包,两种情况下的错误都是一样的。

这是我正在尝试执行的一段代码,我已经安装了所有必要的模块 pywin32、pyttsx3、pyaudio、speechrecognition 一切。

import pyttsx3 
**engine = pyttsx3.init() 
engine.say('Hello sir, how may I help you, sir.')   
engine.runAndWait()** 

*it is giving error as:*

Traceback (most recent call last):
  File "C:\Users\Satyam Kumar Pandey\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\__init__.py", line 20, in init
    eng = _activeEngines[driverName]
  File "C:\Users\Satyam Kumar Pandey\AppData\Local\Programs\Python\Python38-32\lib\weakref.py", line 131, in __getitem__
    o = self.data[key]()
KeyError: None

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Satyam Kumar Pandey\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\drivers\sapi5.py", line 3, in <module>
    from comtypes.gen import SpeechLib  # comtypes
ImportError: cannot import name 'SpeechLib' from 'comtypes.gen' (C:\Users\Satyam Kumar Pandey\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\gen\__init__.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\Users\Satyam Kumar Pandey\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 123, in WINFUNCTYPE
    return _win_functype_cache[(restype, argtypes, flags)]
KeyError: (<class 'ctypes.HRESULT'>, (<class 'comtypes.automation.tagVARIANT'>, <class 'ctypes.wintypes.LP_c_long'>), 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:/Users/Satyam Kumar Pandey/Desktop/assistant/a.py", line 7, in <module>
    engine = pyttsx3.init()
  File "C:\Users\Satyam Kumar Pandey\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\__init__.py", line 22, in init
    eng = Engine(driverName, debug)
  File "C:\Users\Satyam Kumar Pandey\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
    self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
  File "C:\Users\Satyam Kumar Pandey\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\driver.py", line 50, in __init__
    self._module = importlib.import_module(name)
  File "C:\Users\Satyam Kumar Pandey\AppData\Local\Programs\Python\Python38-32\lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\Satyam Kumar Pandey\AppData\Local\Programs\Python\Python38-32\lib\site-packages\pyttsx3\drivers\sapi5.py", line 6, in <module>
    engine = comtypes.client.CreateObject("SAPI.SpVoice")
  File "C:\Users\Satyam Kumar Pandey\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\__init__.py", line 250, in CreateObject
    return _manage(obj, clsid, interface=interface)
  File "C:\Users\Satyam Kumar Pandey\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\__init__.py", line 188, in _manage
    obj = GetBestInterface(obj)
  File "C:\Users\Satyam Kumar Pandey\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\__init__.py", line 110, in GetBestInterface
    mod = GetModule(tlib)
  File "C:\Users\Satyam Kumar Pandey\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\_generate.py", line 110, in GetModule
    mod = _CreateWrapper(tlib, pathname)
  File "C:\Users\Satyam Kumar Pandey\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\_generate.py", line 184, in _CreateWrapper
    mod = _my_import(fullname)
  File "C:\Users\Satyam Kumar Pandey\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\client\_generate.py", line 24, in _my_import
    return __import__(fullname, globals(), locals(), ['DUMMY'])
  File "C:\Users\Satyam Kumar Pandey\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\gen\_C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4.py", line 670, in <module>        
    ISpeechBaseStream._methods_ = [
  File "C:\Users\Satyam Kumar Pandey\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\__init__.py", line 329, in __setattr__
    self._make_methods(value)
  File "C:\Users\Satyam Kumar Pandey\AppData\Local\Programs\Python\Python38-32\lib\site-packages\comtypes\__init__.py", line 698, in _make_methods
    prototype = WINFUNCTYPE(restype, *argtypes)
  File "C:\Users\Satyam Kumar Pandey\AppData\Local\Programs\Python\Python38-32\lib\ctypes\__init__.py", line 125, in WINFUNCTYPE
    class WinFunctionType(_CFuncPtr):
TypeError: item 1 in _argtypes_ passes a union by value, which is unsupported.

最佳答案

尝试使用较低版本的 pyttsx3。请执行下列操作:

pip uninstall pyttsx3
pip install pyttsx3==2.6

关于python - 我在运行一个简单的 pyttsx3 示例时遇到错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60554037/

相关文章:

python - 如何提高 Trac 的性能

python - 返回最长摆动子数组

python - 在 Django 中运行单元测试时出现无效语法错误

json - python 从 json 中提取特定的键和值不起作用

python - 如何在python中将数据库从cPanel连接到桌面

python - 从 float 转换为百分比

python - Django - 无法为具有动态 upload_to 值的 ImageField 创建迁移

python - 文件选择器打开时无需单击子窗口上的按钮

python - 访问字典中数组中嵌套的数据

linux pip包安装报错