gpt4 book ai didi

python - 我在 python 中使用 pyttsx3 时收到 "member not found"错误

转载 作者:太空宇宙 更新时间:2023-11-03 21:20:12 25 4
gpt4 key购买 nike

我正在使用 Visual Studio 2017 并创建一个 Python 应用程序。我在 python 中使用 pyttsx3 时收到“未找到成员”错误。该方法前几次被成功调用,然后调用错误,并且我无法进一步调用该方法。有人可以帮忙吗?

我尝试在 Python 3.6(64 位)和 Python 3.7(32 位)环境中更新 pyttsx3 模块。

我也尝试过“win32com module not found”问题中的答案。我仍然收到错误

def Say(text):
try:
speechEngine = pyttsx3.init()
speechEngine.setProperty('rate', 150)
print("{0} | Lola: {1}".format(TimeOfDay(), text))
speechEngine.say(text)
speechEngine.runAndWait()
logging.info("Spoken words ({0})".format(text))
except Exception as e:
logging.error("Exception occurred", exc_info=True)
print("{0} | Lola: {1}".format(TimeOfDay(),"I have come across an error in my code. See the log for details"))

预期的结果是它应该说出输出文本。但是,我收到以下错误:

我收到以下错误:

Exception occurred
Traceback (most recent call last):

File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\pyttsx3\__init__.py", line 44, in init
eng = _activeEngines[driverName]

File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\weakref.py", line 137, in __getitem__
o = self.data[key]()

KeyError: None

在处理上述异常的过程中,又发生了一个异常:

 Traceback (most recent call last):

File "C:\Users\IllyS\OneDrive\Programming\My Programs\GitHub\Lola-Mark-II\Lola\Lola.py", line 23, in Say
speechEngine = pyttsx3.init()

File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\pyttsx3\__init__.py", line 46, in init
eng = Engine(driverName, debug)

File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\pyttsx3\engine.py", line 52, in __init__
self.proxy = driver.DriverProxy(weakref.proxy(self), driverName, debug)

File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\pyttsx3\driver.py", line 77, in __init__
self._driver = self._module.buildDriver(weakref.proxy(self))

File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\pyttsx3\drivers\sapi5.py", line 22, in buildDriver
return SAPI5Driver(proxy)

File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\pyttsx3\drivers\sapi5.py", line 41, in __init__
self.setProperty('voice', self.getProperty('voice'))

File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\pyttsx3\drivers\sapi5.py", line 72, in getProperty
return self._tts.Voice.Id

File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\win32com\client\__init__.py", line 474, in __getattr__
return self._ApplyTypes_(*args)

File "C:\Program Files (x86)\Microsoft Visual Studio\Shared\Python36_64\lib\site-packages\win32com\client\__init__.py", line 467, in _ApplyTypes_
self._oleobj_.InvokeTypes(dispid, 0, wFlags, retType, argTypes, *args),
pywintypes.com_error: (-2147352567, 'Exception occurred.', (0, None, 'Member not found.', None, 0, -2147201001), None)

最佳答案

我修正了错误。这是因为我在方法中一遍又一遍地调用 speechEngine = pyttsx3.init()speechEngine.setProperty('rate', 150) (因为我有一个while 循环调用此方法)。我把它们搬到外面,效果很好。目前在任何时间后都没有看到错误。看看进展如何......

关于python - 我在 python 中使用 pyttsx3 时收到 "member not found"错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54349050/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com