Code example for TextToSpeech

Methods: setPitch, setSpeechRate, speak

0
 
    public void onClickSpeech(View v) {
	if (mTts != null) {
	    Log.v(TAG, "pitch=" + pitch);
	    Log.v(TAG, "rate=" + rate);
	    if (mTts.setPitch(pitch) == TextToSpeech.ERROR) {
		Log.e(TAG, "tts setPitch error");
	    } 
	    if (mTts.setSpeechRate(rate) == TextToSpeech.ERROR) {
		Log.e(TAG, "tts setSpeechRate error");
	    } 
	    String romaji = KanaToRomaji.toRomaji(text_kana.getText().toString());
	    text_romaji.setText(romaji);
	    mTts.speak(romaji, TextToSpeech.QUEUE_ADD, null);
	} 
    } 
 
    @Override 
    protected void onDestroy() { 
	if (mTts != null) {
	    mTts.shutdown();