我希望在python文本语音中使用 tamil 语音,但我无法将语音从默认语言更改为任何其他语言。我试过这段代码
import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty('voices')
for voice in voices:
if voice.id == 'tamil':
engine.setProperty('voice', voice.id)
print(engine.getProperty('voice'))
break
但是print语句仍然打印默认值。
答案 0 :(得分:0)
我试图解决您的问题,并得出结论,当您运行该行时:
engine.runAndWait()
那是在变量引擎中设置参数的时候。 因此,您可以尝试下一个代码:
import pyttsx3;
engine = pyttsx3.init();
voices = engine.getProperty('voices')
idVoice = 0
for voice in voices:
idVoice = idVoice + 1
if voice.id == 'tamil':
print("void ID: ", voice.id)
engine.setProperty('voice', voice.id)
engine.say("My new message...")
engine.runAndWait()
print(engine.getProperty('voice'))
break
print(idVoice)
engine.setProperty('rate',170)
engine.setProperty('volume', 0.9)
print("The new voice: ", engine.getProperty('voice'))