使用 pyttsx3转语音 出现Type异常
出现的这个异常百度了很久都没有找到解决方法 重装也不行 类型错误 但是 试了很多别的类型 也是不行代码:
import pyttsx3
text = 'text one'
voice = pyttsx3.init()
voice.say(text)
voice.runAndWait()
错误代码
Traceback (most recent call last):
File "F:\python\lib\site-packages\pyttsx3\__init__.py", line 20, in init
eng = _activeEngines
File "F:\python\lib\weakref.py", line 137, in __getitem__
o = self.data()
KeyError: None
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "F:\python\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' (F:\python\lib\site-packages\comtypes\gen\__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "F:\python\lib\ctypes\__init__.py", line 121, in WINFUNCTYPE
return _win_functype_cache[(restype, argtypes, flags)]
KeyError: (<class 'ctypes.HRESULT'>, (<class 'ctypes.c_long'>, <class 'comtypes.automation.tagVARIANT'>, <class 'comtypes.automation.tagVARIANT'>, <class 'ctypes.c_long'>, <class 'ctypes.c_long'>), 0)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "F:/Python代码存放/py.py", line 5, in <module>
voice = pyttsx3.init()
File "F:\python\lib\site-packages\pyttsx3\__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "F:\python\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "F:\python\lib\site-packages\pyttsx3\driver.py", line 50, in __init__
self._module = importlib.import_module(name)
File "F:\python\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name, package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "F:\python\lib\site-packages\pyttsx3\drivers\sapi5.py", line 6, in <module>
engine = comtypes.client.CreateObject("SAPI.SpVoice")
File "F:\python\lib\site-packages\comtypes\client\__init__.py", line 250, in CreateObject
return _manage(obj, clsid, interface=interface)
File "F:\python\lib\site-packages\comtypes\client\__init__.py", line 188, in _manage
obj = GetBestInterface(obj)
File "F:\python\lib\site-packages\comtypes\client\__init__.py", line 110, in GetBestInterface
mod = GetModule(tlib)
File "F:\python\lib\site-packages\comtypes\client\_generate.py", line 110, in GetModule
mod = _CreateWrapper(tlib, pathname)
File "F:\python\lib\site-packages\comtypes\client\_generate.py", line 184, in _CreateWrapper
mod = _my_import(fullname)
File "F:\python\lib\site-packages\comtypes\client\_generate.py", line 24, in _my_import
return __import__(fullname, globals(), locals(), ['DUMMY'])
File "F:\python\lib\site-packages\comtypes\gen\_C866CA3A_32F7_11D2_9602_00C04F8EE628_0_5_4.py", line 128, in <module>
( ['out', 'retval'], POINTER(SpeechWordPronounceable), 'WordPronounceable' )),
File "F:\python\lib\site-packages\comtypes\__init__.py", line 329, in __setattr__
self._make_methods(value)
File "F:\python\lib\site-packages\comtypes\__init__.py", line 698, in _make_methods
prototype = WINFUNCTYPE(restype, *argtypes)
File "F:\python\lib\ctypes\__init__.py", line 123, in WINFUNCTYPE
class WinFunctionType(_CFuncPtr):
TypeError: item 2 in _argtypes_ passes a union by value, which is unsupported. import pyttsx3
text = '你好'
voice = pyttsx3.init("dummy")
voice.say(text)
voice.runAndWait() zltzlt 发表于 2020-2-16 15:47
没有报错 但是没有任何返回 也没有任何声音 admintest166 发表于 2020-2-16 15:52
没有报错 但是没有任何返回 也没有任何声音
那就用这段代码(先安装 Pywin32 库):
import win32com.client
text = "Hello" # 要播报的文本
speaker = win32com.client.Dispatch("SAPI.SpVoice")
speaker.Speak(text) 这个Pywin32 库可以正常使用 就是pyttsx3 不行 zltzlt 发表于 2020-2-16 16:03
那就用这段代码(先安装 Pywin32 库):
我好像发现 python3.7.6 在运行voise=pyttsx3.init()的时候就报错了
但是用3.7.3却没有任何问题会不会是3.7.6不支持pyttsx3 admintest166 发表于 2020-2-16 16:27
我好像发现 python3.7.6 在运行voise=pyttsx3.init()的时候就报错了
但是用3.7.3却没有任何问题会不会 ...
应该是吧,不过用 PyWin32 可以 请问楼主这个问题解决了吗我用pyttsx3也是和你一样的报错
4280099 发表于 2021-4-11 16:13
请问楼主这个问题解决了吗我用pyttsx3也是和你一样的报错
这是输入的代码
import pyttsx3
engine=pyttsx3.init()
engine.say('Sally sells seashells by the seashore.')
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()
页:
[1]