【问题标题】:want to change voice to Siri male in pyttsx3想在 pyttsx3 中将声音更改为 Siri 男性
【发布时间】:2020-08-05 08:01:23
【问题描述】:
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 

【问题讨论】:

  • 只有2个声音Microsoft David Desktop - English (United States)Microsoft Zira Desktop - English (United States)没有Siri

标签: python voice siri pyttsx


【解决方案1】:

你这样设置声音:

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)

【讨论】:

    猜你喜欢
    • 2018-04-28
    • 2017-12-05
    • 2022-10-07
    • 2021-04-21
    • 1970-01-01
    • 1970-01-01
    • 2021-09-03
    • 2011-03-04
    • 2017-10-10
    相关资源
    最近更新 更多