Reputation: 1669
I want to know how to text-to-speech Chinese using the python package 'pyttsx'. It seems to need some other modules like neospeech.
Upvotes: 2
Views: 3907
Reputation: 12920
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()
Upvotes: 0
Reputation: 1669
Yes, neospeech is a language library. By installing it, you can just set the voice of pyttsx and tts Chinese as well.
Upvotes: 1