我将pyttsx3模块用于类似Alexa的项目。我写的源代码在我自己的电脑上都运行得很好,但现在我正试图让它在Pi上运行
import pyttsx3
engine = pyttsx3.init()
nl_voice_id = "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\MSTTS_V110_nlNL_Frank" # Dutch Voice..
voices = engine.getProperty('voices')
engine.setProperty('voice', nl_voice_id)
def talk(text):
engine.say(text)
engine.runAndWait()
talk('test')
没有什么特别之处,但当我在基于64位的Python版本上运行此代码时,我会遇到以下错误:
Traceback (most recent call last):
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\pyttsx3\__init__.py", line 20, in init
eng = _activeEngines[driverName]
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\weakref.py", line 134, 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\user\AppData\Local\Programs\Python\Python39\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\user\AppData\Local\Programs\Python\Python39\lib\site-packages\comtypes\gen\__init__.py)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\user\Documents\user\user-master\userv2\user\Static\test.py", line 3, in <module>
engine = pyttsx3.init()
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\pyttsx3\__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\pyttsx3\driver.py", line 50, in __init__
self._module = importlib.import_module(name)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\importlib\__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 790, in exec_module
File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\pyttsx3\drivers\sapi5.py", line 6, in <module>
engine = comtypes.client.CreateObject("SAPI.SpVoice")
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\comtypes\client\__init__.py", line 238, in CreateObject
obj = comtypes.CoCreateInstance(clsid, clsctx=clsctx, interface=interface)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\site-packages\comtypes\__init__.py", line 1219, in CoCreateInstance
_ole32.CoCreateInstance(byref(clsid), punkouter, clsctx, byref(iid), byref(p))
File "_ctypes/callproc.c", line 1010, in GetResult
OSError: [WinError -2147024703] %1 is not a valid Win32 application
吸引我注意的是最后一行:OSError: [WinError -2147024703] %1 is not a valid Win32 application
因此,我尝试使用32位Python版本运行完全相同的程序。这起作用了。但我需要它在64位上工作,因为我的实际程序中安装了一些其他模块,其他模块无法正常工作
我还尝试卸载pytts3x并安装带有pip install pyttsx3==2.71
的2.71版本,这给了我一个pywintypes_com错误
Traceback (most recent call last):
File "C:\Users\Kali\AppData\Local\Programs\Python\Python39\lib\site-packages\pyttsx3\__init__.py", line 20, in init
eng = _activeEngines[driverName]
File "C:\Users\Kali\AppData\Local\Programs\Python\Python39\lib\weakref.py", line 134, in __getitem__
o = self.data[key]()
KeyError: 'sapi5'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Kali\AppData\Local\Programs\Python\Python39\lib\site-packages\win32com\client\dynamic.py", line 81, in _GetGoodDispatch
IDispatch = pythoncom.connect(IDispatch)
pywintypes.com_error: (-2147221021, 'Operation unavailable', None, None)
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\Kali\Documents\Kali\Kali-master\Kaliv2\Kali\Static\test.py", line 3, in <module>
engine = pyttsx3.init("sapi5")
File "C:\Users\Kali\AppData\Local\Programs\Python\Python39\lib\site-packages\pyttsx3\__init__.py", line 22, in init
eng = Engine(driverName, debug)
File "C:\Users\Kali\AppData\Local\Programs\Python\Python39\lib\site-packages\pyttsx3\engine.py", line 30, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)
File "C:\Users\Kali\AppData\Local\Programs\Python\Python39\lib\site-packages\pyttsx3\driver.py", line 52, in __init__
self._driver = self._module.buildDriver(weakref.proxy(self))
File "C:\Users\Kali\AppData\Local\Programs\Python\Python39\lib\site-packages\pyttsx3\drivers\sapi5.py", line 23, in buildDriver
return SAPI5Driver(proxy)
File "C:\Users\Kali\AppData\Local\Programs\Python\Python39\lib\site-packages\pyttsx3\drivers\sapi5.py", line 28, in __init__
self._tts = win32com.client.Dispatch('SAPI.SPVoice')
File "C:\Users\Kali\AppData\Local\Programs\Python\Python39\lib\site-packages\win32com\client\__init__.py", line 95, in Dispatch
dispatch, userName = dynamic._GetGoodDispatchAndUserName(dispatch,userName,clsctx)
File "C:\Users\Kali\AppData\Local\Programs\Python\Python39\lib\site-packages\win32com\client\dynamic.py", line 98, in _GetGoodDispatchAndUserName
return (_GetGoodDispatch(IDispatch, clsctx), userName)
File "C:\Users\Kali\AppData\Local\Programs\Python\Python39\lib\site-packages\win32com\client\dynamic.py", line 83, in _GetGoodDispatch
IDispatch = pythoncom.CoCreateInstance(IDispatch, None, clsctx, pythoncom.IID_IDispatch)
pywintypes.com_error: (-2147024703, 'OLE error 0x800700c1', None, None)
我试图解决这个pywintypes错误,但没有成功
我还能试什么
当我在Pi上安装Raspbian(32位)时,不幸的是,我得到了相同的错误。我认为Pyttsx3是一个非常好的模块,但不适合Pi。所以我做了一些研究,为Python找到另一个文本到语音(TTS)模块。我遇到了gTTS,它也是一个很好的模块,易于集成。它使用谷歌翻译,因此您可以从每种谷歌翻译语言中进行选择
这是我目前的解决办法。如果有人能回答为什么pyttsx3不使用Pi,请告诉我。虽然gTTS很棒,但我更喜欢Sapi5
目前没有回答
相关问题 更多 >
编程相关推荐