Question

I am learning to write an app that is intended to perform TTS on given strings, and have tried an example modified from web:

Coding as follows:

// setup TTS part 1
            mTts = new TextToSpeech(Lesson2_dialog_revision_simple.this, this);  // TextToSpeech.OnInitListener
            speakBtn.setOnClickListener(new OnClickListener() 
            {         
                public void onClick(View v) 
                {  
                    StringTokenizer loveTokens = new StringTokenizer("他們 one two是 three ",",.");  
                    int i = 0;  
                    loveArray = new String[loveTokens.countTokens()];  
                    while(loveTokens.hasMoreTokens())  
                    {  
                        loveArray[i++] = loveTokens.nextToken();  
                    }  
                    speakText();  
                }  
            });        
    }

// setup TTS part 2 
    @Override
    public void onUtteranceCompleted(String utteranceId) 
    {  
        Log.v(TAG, "Get completed message for the utteranceId " + utteranceId);  
        lastUtterance = Integer.parseInt(utteranceId);  
    }  

// setup TTS part 3 
    @Override
    public void onInit(int status) 
    {  
        if(status == TextToSpeech.SUCCESS)  
        {  
            int result = mTts.setLanguage(Locale.CHINESE);  // <====== set speech location
            if(result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED)  
            {  
                Toast.makeText(Lesson2_dialog_revision_simple.this, "Language is not supported", Toast.LENGTH_LONG).show();
                speakBtn.setEnabled(false);  
            }  
            else  
            {  
                speakBtn.setEnabled(true);  
                mTts.setOnUtteranceCompletedListener(this);  
            }  
        }     
    }  

// setup TTS part 4 
    private void speakText()  
    {  
        lastUtterance++;  
        if(lastUtterance >= loveArray.length)  
        {  
            lastUtterance = 0;  
        }  
        Log.v(TAG, "the begin utterance is " + lastUtterance);  
        for(int i = lastUtterance; i < loveArray.length; i++)  
        {  
            params.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, String.valueOf(i));  
            mTts.speak(loveArray[i], TextToSpeech.QUEUE_ADD, params);  
        }  
    }  

Questions:

Everything is ok if the int result = mTts.setLanguage(Locale.US); in part 3 above is set as US and to read out "one two three" in English perfectly. (in the above example, it will skip all the chinese words and just read out one two three)

However, if I change the string to read out Chinese by setting language as setLanguage(Locale.CHINESE), it immediately toasts out that "Language is not supported".

I would like to ask

  1. the current TTS still does not support Chinese? I would even more prefer Cantonese rather than Chinese.

  2. The phone is ABLE to recognize Cantonese when I inputting messages via speech (Cantonese). Is it actually there are some other way to perform TTS with output being Cantonese?

Thanks!!

Was it helpful?

Solution

1 - The Google TTS Engine at its current version does not support Cantonese as output yet. Putonghua works fine.

2 - Ekho is a TTS Engine that supports Cantonese.

You might want to give a try on the TTS app I developed that works with Ekho and Google TTS Engine: Voice Out TTS

As far as I know there's no specific Locale in JAVA to distinguish between Cantonese or Putonghua because Cantonese is a Chinese dialect. The Locale in JAVA refers only to the writings (Simplified or Traditional).

For example you can read a string written in Traditional Chinese with Cantonese or Putonghua.

OTHER TIPS

@Pearmak: you can check the language that are supported in your device

int i = mTts.isLanguageAvailable(Locale.ENGLISH);

where mTts is object of TextToSpeech

If you get the value of i >=0 then that language is supported on you device otherwise not.

You may also pass the language locale string.

int i = mTts.isLanguageAvailable(new Locale("zh_CN")); //for chinese simplified

Yue, a tiny Chinese text to speech (TTS) synthesis engine of Cantonese, Mandarin for offline embedded system. Yue is extremely small size, offline, independent, and PCM audio output no needs of server or network connection. It has high naturalness of synthesised voice for hybrid text input, the Cantonese and Mandarin speech synthesis for same text input, with Yale, Jyutping and Pinyin romanization. The engine can continues produce and play voice for long text, the length of the text without limit. It has build-in intelligent detecter that can handle any traditional Chinese, simplified Chinese, English, number and punctuations, symbol mixed text input. Yue is written in ANSI C, no dependent of third part library, running on ARM, AVR embedded system such as watch, toy, robot and iPhone, Android, … mobile platforms, of course normal desktops, ebook, news paper reader, story teller. Yue can be loaded into memory and embedded in other programs, because of its extremely small size, it is well suited to embedded systems, and is also suitable for desktop operating systems. The engine can have bindings for a large number of programming languages.

The link:http://www.sevenuc.com/en/tts.html

some phones have the cantonese locale that you can use with TTS.

try

new Locale("yue", "HK"); //yue for 粤语

Once you have set the system language to Cantonese, then you can use setLanguage(Locale.getDefault()).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top