3

Show all available voice in pyttsx3:

import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty('voices')
voices[-2].id
'Mandarin'

I want to play a Chinese string with Mandarin

import pyttsx3
engine = pyttsx3.init()
voices = engine.getProperty('voices')
engine.setProperty("voice", voices[-2].id)
engine.say('你好你好你好你好')
engine.runAndWait()

I have recorded the voice played by pyttsx3 and upload it to Dropbox. As you can hear if you listen to the recording, it is not Mandarin.

How can I fix my code?

Play the string with espeak and record, upload into dropbox, please download and listen to it.

espeak -vzh  '你好你好你好你好'

created by espeak in Madarian which is what I want to get

Alex Waygood
  • 6,304
  • 3
  • 24
  • 46
showkey
  • 482
  • 42
  • 140
  • 295

2 Answers2

2

I must say the module pyttsx3 looks like it's not responding well to language changes. The synthesizer is aweful and something was missing.

Until I encountered gtts lib.

In order to get all supported languages use the following: print(gtts.lang.tts_langs())

Which will output:

{'af': 'Afrikaans', 'ar': 'Arabic', 'bg': 'Bulgarian', 'bn': 'Bengali', 'bs': 'Bosnian', 'ca': 'Catalan', 'cs': 'Czech', 'cy': 'Welsh', 'da': 'Danish', 'de': 'German', 'el': 'Greek', 'en': 'English', 'eo': 'Esperanto', 'es': 'Spanish', 'et': 'Estonian', 'fi': 'Finnish', 'fr': 'French', 'gu': 'Gujarati', 'hi': 'Hindi', 'hr': 'Croatian', 'hu': 'Hungarian', 'hy': 'Armenian', 'id': 'Indonesian', 'is': 'Icelandic', 'it': 'Italian', 'ja': 'Japanese', 'jw': 'Javanese', 'km': 'Khmer', 'kn': 'Kannada', 'ko': 'Korean', 'la': 'Latin', 'lv': 'Latvian', 'mk': 'Macedonian', 'ml': 'Malayalam', 'mr': 'Marathi', 'my': 'Myanmar (Burmese)', 'ne': 'Nepali', 'nl': 'Dutch', 'no': 'Norwegian', 'pl': 'Polish', 'pt': 'Portuguese', 'ro': 'Romanian', 'ru': 'Russian', 'si': 'Sinhala', 'sk': 'Slovak', 'sq': 'Albanian', 'sr': 'Serbian', 'su': 'Sundanese', 'sv': 'Swedish', 'sw': 'Swahili', 'ta': 'Tamil', 'te': 'Telugu', 'th': 'Thai', 'tl': 'Filipino', 'tr': 'Turkish', 'uk': 'Ukrainian', 'ur': 'Urdu', 'vi': 'Vietnamese', 'zh-CN': 'Chinese', 'zh-TW': 'Chinese (Mandarin/Taiwan)', 'zh': 'Chinese (Mandarin)'}

As you can see at the end 'zh': 'Chinese (Mandarin)' Mandarine language denoted with simply 'zh'

Your code should look like that:

from gtts import gTTS

mytext = '你好你好你好你好'
language = 'zh'

myobj = gTTS(text=mytext, lang=language, slow=False)
# save to local folder:
myobj.save("mandarine_female_voice.mp3")

I checked your dropbox recording and it does say the same thing in my example.

Pavel Gomon
  • 213
  • 1
  • 7
0

I run pyttsx3 in Ubuntu 20.04.4 LTS,the voices[ ].id is Mandarin. But after I trace the code, I find even I set the setProperty as Mandarin, pyttsx3 still use "default" to be get in getProperty. So try to modify the /usr/lib/aarch64-linux-gnu/espeak-data/voices/default as below.

name default

language asia-zh

gender male

And modify the python code "engine.setProperty('voice', voices[-2].id)" to "engine.setProperty('voice', 'zh')", then it works!