python - 想在 pyttsx3 中将声音更改为 Siri 男性
问题描述
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
解决方案
你这样设置声音:
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty('voice', voices[i].id)
其中i
是一个整数,指向您安装的 Siri 语音之一。
你可以用这个来测试不同的声音,例如:
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)
输入一个整数,然后按 Enter 听到声音。
或者,如果您想遍历所有已安装的声音,您可以这样做:
import pyttsx3
text = "Greetings Professor Falken"
engine = pyttsx3.init()
voices = engine.getProperty('voices')
for voice in voices:
try:
i = voices.index(voice)
engine.setProperty('voice', voices[i].id)
engine.say(text)
engine.runAndWait()
print(str(i)+") "+engine.getProperty('voice'))
except Exception as e:
print(e)
推荐阅读
- javascript - Buildfire:音频播放器服务未创建 timeUpdate 事件
- javascript - 为什么 Bitwise OR 在我的 Jest 测试中不起作用
- javascript - 如何修复此 Fetch api 错误:未捕获(承诺中) SyntaxError: Unexpected token < in JSON at position 0?
- python - 基于特定键和值的子集复杂嵌套字典
- oracle - 基于字段的匹配算法分数
- r - R ggplot2瀑布问题
- redirect - IIS 重定向映射不适用于根目标
- jquery - jQuery UI Datepicker - 如何动态禁用特定日期
- docker - 谷歌云构建语法
- haskell - 如何将具有两个生成器的列表推导重新表达为两个具有一个生成器的列表推导并获得相同的结果?