我目前正在开发具有多处理和 pyttsx3 的 TTS 应用程序。如果我尝试启动一个进程并将 pyttsx3.init("sapi5") 对象作为参数传递,以便使用它在目标函数中说话,它会因为酸洗和 PermissionError 而返回 TypeError。这是一个复制示例:
import pyttsx3
def dummy(engine):
engine.say("test")
engine.runAndWait()
if __name__ == "__main__":
multiprocessing.Process(target=dummy, args=(pyttsx3.init("sapi5"),)).start()
以及产生的错误:
D:/Python3.9.2_x64/python.exe "d:/VSCode Projects/TTS/test2.py"
Traceback (most recent call last):
File "d:\VSCode Projects\TTS\test2.py", line 9, in <module>
multiprocessing.Process(target=dummy, args=(pyttsx3.init("sapi5"),)).start()
File "D:\Python3.9.2_x64\lib\multiprocessing\process.py", line 121, in start
self._popen = self._Popen(self)
File "D:\Python3.9.2_x64\lib\multiprocessing\context.py", line 224, in _Popen
return _default_context.get_context().Process._Popen(process_obj)
File "D:\Python3.9.2_x64\lib\multiprocessing\context.py", line 327, in _Popen
return Popen(process_obj)
File "D:\Python3.9.2_x64\lib\multiprocessing\popen_spawn_win32.py", line 93, in __init__
reduction.dump(process_obj, to_child)
File "D:\Python3.9.2_x64\lib\multiprocessing\reduction.py", line 60, in dump
ForkingPickler(file, protocol).dump(obj)
TypeError: cannot pickle 'module' object
D:\VSCode Projects>Traceback (most recent call last):
File "<string>", line 1, in <module>
File "D:\Python3.9.2_x64\lib\multiprocessing\spawn.py", line 107, in spawn_main
new_handle = reduction.duplicate(pipe_handle,
File "D:\Python3.9.2_x64\lib\multiprocessing\reduction.py", line 79, in duplicate
return _winapi.DuplicateHandle(
PermissionError: [WinError 5] Zugriff verweigert
注意:“Zugriff verweigert”是英文的“Access denied”
PS:这是我的第一个问题,请随时提供反馈