首页 > 解决方案 > 运行函数 pyttsx3 文本到语音导致应用程序关闭

问题描述

每次将意大利语单词插入列表框时,我都会运行文本到语音功能。在发音所有单词后,有时 python 脚本会失败。有时在发音所有单词后,所有插入列表框的操作都完成了,没有任何失败。由于单词是通过循环插入到列表框中的,因此人们会期望单词后面跟着它的发音,因为每个单词都会调用parla_italiano() 。但似乎该函数正在持有另一个 python 线程。我还没有使用过线程。有没有办法在发音后释放这个功能,并允许单词插入到列表框中?我在 windows10 上使用 python 3.9

def parla_italiano(phrase):
    import pyttsx3
    engine = pyttsx3.init() 
    it_voice_id = r"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_IT-IT_ELSA_11.0"
    engine.setProperty('voice', it_voice_id)
    engine.say(phrase)
    engine.runAndWait()

这是错误消息:

Fatal Python error: PyEval_RestoreThread: the function must be called with the GIL held, but the GIL is released (the current Python thread state is NULL)
Python runtime state: initialized

标签: pythontext-to-speechpython-multithreadingpyttsx3

解决方案


推荐阅读