问题描述
在python中使用Pyttsx模块时,如何更改播放文本时使用的语音ID?
When using the Pyttsx module within python, how do you change the voice ID that is used when playing out text?
提供的文档说明了如何在所有可用的声音中循环,但没有说明如何选择特定的声音.
The documentation provided illustrates how to cycle through all the available voices, but does not make clear how to choose a specific one.
推荐答案
呃,你应该使用 engine.setProperty('voice', voice_id)
(voice_id
是系统中语音的 ID;您可以从 engine.getProperty('voices')
) 中获取可用语音列表,如 那个例子:
Uh, you should use engine.setProperty('voice', voice_id)
(with voice_id
being an ID of the voice in your system; you can grab the list of available voices from engine.getProperty('voices')
) as proposed in that example:
engine = pyttsx.init()
voices = engine.getProperty('voices')
for voice in voices:
engine.setProperty('voice', voice.id) # changes the voice
engine.say('The quick brown fox jumped over the lazy dog.')
engine.runAndWait()
你不必循环,你可以在没有for
循环的情况下设置语音ID.
就这样做:
You don't have to cycle, you can set voice id without a for
loop.
Just do it like that:
engine = pyttsx.init()
engine.setProperty('voice', voice_id) # use whatever voice_id you'd like
engine.say('The quick brown fox jumped over the lazy dog.')
这篇关于在 python 中使用 PYTTSX 模块更改语音的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!