RapidWareTech / pyttsx

Cross-platform text-to-speech wrapper
Other
370 stars 134 forks source link

How to use pyttsx to play the Chinese? #50

Open Near-Tam opened 8 years ago

Near-Tam commented 8 years ago

Can pyttsx play Chinese? If so, what should do that? Do I need to install the Chinese library? If so, how do I download and install?

nickgermaine commented 8 years ago

I have no idea. I've just taken over this project, and honestly, haven't had much time to familiarize myself with the code yet.

spreadred commented 7 years ago

Perhaps this is pertinent?

https://stackoverflow.com/questions/18715563/how-to-tts-chinese-using-pyttsx

WickyLeo commented 7 years ago

voices = ['com.apple.speech.synthesis.voice.mei-jia', 'com.apple.speech.synthesis.voice.sin-ji.premium', 'com.apple.speech.synthesis.voice.ting-ting']; In Mac OS,there are all chinese voice,choose one your want.and then: engine = pyttsx.init() engine.setProperty('voice', random.choice(voices)) engine.say(u'你好') engine.runAndWait()

It‘s OK.

sincethenn commented 3 years ago

I want to play chances in ubuntu, I found it actually always said "chinese letter letter letter ..." and so on. The last 2 voices are: <Voice id=Mandarin

          name=Mandarin
          languages=[b'\x05zh']
          gender=male
          age=None>
<Voice id=cantonese
          name=cantonese
          languages=[b'\x05zh-yue']
          gender=male
          age=None>

The script is

import pyttsx3

engine = pyttsx3.init()
voices = engine.getProperty('voices')
for voice in voices:
    print(voice)
engine.setProperty('voice', voices[-2].id)
engine.say("你好")
engine.runAndWait()
tomtan0817 commented 2 years ago

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!

I want to play chances in ubuntu, I found it actually always said "chinese letter letter letter ..." and so on. The last 2 voices are: <Voice id=Mandarin

          name=Mandarin
          languages=[b'\x05zh']
          gender=male
          age=None>
<Voice id=cantonese
          name=cantonese
          languages=[b'\x05zh-yue']
          gender=male
          age=None>

The script is

import pyttsx3

engine = pyttsx3.init()
voices = engine.getProperty('voices')
for voice in voices:
    print(voice)
engine.setProperty('voice', voices[-2].id)
engine.say("你好")
engine.runAndWait()
jfthuong commented 1 year ago

I have created a small function help find a voice in Chinese:

import pyttsx3
from pyttsx3.voice import Voice

def get_chinese_voice(engine: pyttsx3.engine.Engine) -> Voice:
    voices = engine.getProperty("voices")
    for voice in voices:
        if voice.languages and voice.languages[0] == "zh-CN":
            return voice
        if "Chinese" in voice.name or "Mandarin" in voice.name.title():
            return voice

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

You can use as such:

tts_engine = pyttsx3.init()
chinese_voice = get_chinese_voice(tts_engine)
tts_engine.setProperty("voice", chinese_voice.id)