Python Pyttsx,我能';不要改变代码中的性别…,我';我做错了?
第一个很棒的lib!我在linux下使用,而且很容易启动,但现在我想将演讲改为女性。。。我正在尝试下面的代码,但没有成功。。。你能帮帮我吗Python Pyttsx,我能';不要改变代码中的性别…,我';我做错了?,python,text-to-speech,Python,Text To Speech,第一个很棒的lib!我在linux下使用,而且很容易启动,但现在我想将演讲改为女性。。。我正在尝试下面的代码,但没有成功。。。你能帮帮我吗 import pyttsx def say(text): print "{}".format(text) engine = pyttsx.init() engine.setProperty('rate', 100) voices = engine.getProperty('voices') for voice in
import pyttsx
def say(text):
print "{}".format(text)
engine = pyttsx.init()
engine.setProperty('rate', 100)
voices = engine.getProperty('voices')
for voice in voices:
print voice.gender
engine.setProperty('female', voice.gender)
print "change: {}".format(voice.gender)
engine.say(text)
engine.runAndWait()
引擎没有名为female
的属性,因此将此属性设置为当前语音的性别没有任何意义,正如您所发现的,也没有任何作用
我假设你打算循环浏览所有可用的声音,然后选择你发现的第一个是女性的声音。如果是这样,可能是这样的:
for voice in voices:
if voice.gender == "female"
engine.setProperty('voice', voice.id)
break
您可以尝试下面的代码。这对我来说非常有效:
for voice in voices:
engine.setProperty('voice',voices[1].id)
engine.say("Hello")
engine.runAndWait()
对我来说,在Linux中,将声音改为女性的唯一有效方法是:
voices = speaker.getProperty('voices')
speaker.setProperty('voice', 'english+f4')
speaker.say('Finally, something worked!')
speaker.runAndWait()
对你有用吗?它是有用的…但不会改变任何东西…关于房产你是完全正确的!但是不。。还是男性。。。无论如何,请参阅以下回复:
voices = speaker.getProperty('voices')
speaker.setProperty('voice', 'english+f4')
speaker.say('Finally, something worked!')
speaker.runAndWait()