Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use pyttsx to play the Chinese? #50

Open
Near-Tam opened this issue Nov 9, 2016 · 6 comments
Open

How to use pyttsx to play the Chinese? #50

Near-Tam opened this issue Nov 9, 2016 · 6 comments

Comments

@Near-Tam
Copy link

Near-Tam commented Nov 9, 2016

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
Copy link
Member

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
Copy link

@WickyLeo
Copy link

WickyLeo commented Dec 25, 2016

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
Copy link

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
Copy link

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
Copy link

jfthuong commented Mar 12, 2023

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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

7 participants