此代码有效,但我只能在预装在 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()
voices[] 中只有 0 和 1 作为索引。
我想让“Microsoft Kalpana Mobile”说话。过去 2 个月我一直在从事这个项目。如果这不起作用,我所有的努力都会付之东流。请帮助:(
提前致谢。
最佳答案
你可以试试这段代码:
import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty('voices')
for voice in voices:
print(voice, voice.id)
engine.setProperty('voice', voice.id)
engine.say("Hello World!")
engine.runAndWait()
engine.stop()
然后不用 for 循环,只要选择你喜欢的 voice.id
关于python - 如何改变pyttsx3中的声音?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44858120/