用Python中的PYTTSX模块更改语音
问题描述:
在Python中使用Pyttsx模块时,如何更改播放文本时使用的语音ID?用Python中的PYTTSX模块更改语音
提供的文档说明了如何循环所有可用的声音,但没有说明如何选择特定的声音。
答
呃,你应该使用engine.setProperty('voice', voice_id)
(与voice_id
是在您的系统声音的ID,你可以抓住一个可用声音从engine.getProperty('voices')
名单)作为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。
就那样做:
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.')
答
import pyttsx
engine = pyttsx.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[0].id) #change index to change voices
engine.say('I'm a little teapot...')
engine.runAndWait()
谢谢,这是我试过,但所有目前存在的声音ID的声音完全一样,想知道如果我错过了一些东西明显。 – 2015-02-05 13:42:45