如何更改pyttsx3中的语音?

2024-06-06 22:43:16 发布

您现在位置:Python中文网/ 问答频道 /正文

这段代码正在工作,但我只能在微软Windows中预装的声音之间切换。这些声音是“微软大卫移动”和“微软Zira移动”。

后来我安装了“Microsoft Kalpana Mobile”,并将其设置为默认的Windows语音。但我仍然无法切换到“微软Kalpana移动”。密码是-

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[]中的索引。

我想让“微软Kalpana手机”来说话。我在这个项目上工作了2个月。如果这不起作用,我所有的努力都将付之东流。请帮忙:

提前谢谢。


Tags: 代码import声音密码initwindows语音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循环,只需选择您喜欢的语音.id

我刚刚注意到。要设置语言⇓这只是我的默认语言设置是“ja_JP”。

import pyttsx3

engine = pyttsx3.init()
voices = engine.getProperty('voices')
for voice in voices:
    print voice
    if voice.languages[0] == u'en_US':
        engine.setProperty('voice', voice.id)
        break

engine.say('Hello World')
engine.runAndWait()

或者

voice.name == 'Alex'

相关问题 更多 >