хочу изменить голос на Siri male в pyttsx3 - PullRequest
0 голосов
/ 05 августа 2020
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 

1 Ответ

0 голосов
/ 13 августа 2020

Вы устанавливаете голос следующим образом:

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)
...