How to TTS Chinese using pyttsx

Question:

I want to know how to text-to-speech Chinese using the python package ‘pyttsx’. It seems to need some other modules like neospeech.

Asked By: Booster

||

Answers:

Yes, neospeech is a language library. By installing it, you can just set the voice of pyttsx and tts Chinese as well.

Answered By: Booster

You need to set a voice that supports Chinese before using pyttsx3:

Something like

import pyttsx3


def get_chinese_voice(engine):
    """Get a Chinese voice"""
    voices = engine.getProperty("voices")
    for voice in voices:
        if "zh-CN" in voice.languages:
            return voice
        if "Chinese" in voice.name or "Mandarin" in voice.name.title():
            return voice

    raise KeyError(f"No Chinese voice found among {voices}")


engine = pyttsx3.init()

chinese_voice = get_chinese_voice(engine)
engine.setProperty("voice", chinese_voice.id)
engine.say("你好")
engine.runAndWait()
Answered By: Jean-Francois T.
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.