Python 想在pyttsx3中将语音更改为Siri male吗
您可以这样设置声音:Python 想在pyttsx3中将语音更改为Siri male吗,python,voice,siri,pyttsx,Python,Voice,Siri,Pyttsx,您可以这样设置声音: import pyttsx3 engine = pyttsx3.init() voices = engine.getProperty('voices') for voice in voices: print (voice) if voice.languages[-1] == u'en_us': engine.setProperty('voice', voice.id) engine.say('Hello World') engine.run
import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty('voices')
for voice in voices:
print (voice)
if voice.languages[-1] == u'en_us':
engine.setProperty('voice', voice.id)
engine.say('Hello World')
engine.runAndWait()
#the list docent have Siri included
import pyttsx3
text = "Greetings Professor Falken"
engine = pyttsx3.init()
voices = engine.getProperty('voices')
while True:
try:
user_input = input()
i = int(user_input)
engine.setProperty('voice', voices[i].id)
engine.say(text)
engine.runAndWait()
print(user_input+") "+engine.getProperty('voice'))
except Exception as e:
print(e)
其中,i
是一个整数,指向已安装的Siri语音之一
您可以使用以下方法测试不同的声音,例如:
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[i].id)
输入一个整数,然后按enter键以听到声音
或者,如果您想运行所有已安装的语音,您可以这样做:
import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty('voices')
for voice in voices:
print (voice)
if voice.languages[-1] == u'en_us':
engine.setProperty('voice', voice.id)
engine.say('Hello World')
engine.runAndWait()
#the list docent have Siri included
import pyttsx3
text = "Greetings Professor Falken"
engine = pyttsx3.init()
voices = engine.getProperty('voices')
while True:
try:
user_input = input()
i = int(user_input)
engine.setProperty('voice', voices[i].id)
engine.say(text)
engine.runAndWait()
print(user_input+") "+engine.getProperty('voice'))
except Exception as e:
print(e)
只有两种声音
Microsoft David Desktop-English(美国)
和Microsoft Zira Desktop-English(美国)
没有Siri