pythonwindowsubuntupyttsx3polish

synthesizer in windows sounds much better than in linux (python and pyttsx3)


I've made a simple text_to_speech function in python based on pyttsx3 library (in polish language).

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

When I run this on windows the voice is tolerable, but in linux sounds teribble (windows 10 and ubuntu 18.04, pyttsx==2.9 on both machines).

I've also made for loop to print all available voices:

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)

Output in windows:

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: []

Output in linux:

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

Is there a way to install other polish voices on linux version of pyttsx3 (or maybe other library)?


Solution

  • Ok, I find out that windows synthesizer called sapi5 can't be easily transfered to linux.

    from pyttsx3 docs:

    Version 2.6 of pyttsx3 includes drivers for the following text-to-speech synthesizers. Only operating systems on which a driver is tested and known to work are listed. The drivers may work on other systems.

    • SAPI5 on Windows XP and Windows Vista and Windows 8,8.1 , 10
    • NSSpeechSynthesizer on Mac OS X 10.5 (Leopard) and 10.6 (Snow Leopard)
    • espeak on Ubuntu Desktop Edition 8.10 (Intrepid), 9.04 (Jaunty), and 9.10 (Karmic)

    but I also find out that there is library gTTS which support good sounding polish voice on linux :)