Код: Выделить всё
import pyttsx3 as tts
engine = tts.init()
engine.setProperty('rate', 130)
engine.setProperty('voice', 'polish')
def text_to_speech(text):
engine.say(text)
engine.runAndWait()
(Windows 10 и Ubuntu 18.04, pyttsx==2.9 на обеих машинах).
Я также сделал цикл для печати всех доступных голосов:
Код: Выделить всё
voices = engine.getProperty('voices')
for voice in voices:
print("Voice:")
print("ID: %s" %voice.id)
print("Name: %s" %voice.name)
print("Age: %s" %voice.age)
print("Gender: %s" %voice.gender)
print("Languages Known: %s" %voice.languages)
Код: Выделить всё
Voice: ID: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_PL-PL_PAULINA_11.0 Name: Microsoft Paulina Desktop - Polish Age: None Gender: None Languages Known: [] Voice: ID: HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Speech\Voices\Tokens\TTS_MS_EN-US_ZIRA_11.0 Name: Microsoft Zira Desktop - English (United States) Age: None Gender: None Languages Known: []
Код: Выделить всё
Voice:
ID: english-us
Name: english-us
Age: None
Gender: male
Languages Known: \[b'\\x02en-us'\]
Voice:
ID: polish
Name: polish
Age: None
Gender: male
Languages Known: \[b'\\x05pl'\]
Voice:
ID: brazil
Name: brazil
Age: None
Gender: male
Languages Known: \[b'\\x05pt-br'\]
and a lot of other languages
(...)
Подробнее здесь: https://stackoverflow.com/questions/717 ... nd-pyttsx3