此代码有效,但我只能在 Microsoft Windows 中预安装的声音之间切换。这些声音是“Microsoft David Mobile”和“Microsoft Zira Mobile”。
后来我安装了“Microsoft Kalpana Mobile”并将其设置为默认的 Windows 语音。但我仍然无法切换到“Microsoft Kalpana Mobile”。代码是-
import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id) #changing index changes voices but ony 0 and 1 are working here
engine.say('Hello World')
engine.runAndWait()
只有 0 和 1 在 voices[] 中用作索引。
我想让“Microsoft Kalpana Mobile”说话。过去 2 个月我一直在从事这个项目。如果这不起作用,我所有的努力都会付之东流。请帮忙:(
提前致谢。
原文由 its_neetesh 发布,翻译遵循 CC BY-SA 4.0 许可协议
你可以试试这段代码:
然后代替 for 循环,只需选择您喜欢的 voice.id