2016-03-25 23 views
2

google ttsライブラリを使用してttsアプリを構築しています。私がヒンディー語に言語localeを設定して、アプリケーションに戻ったとき、それは正しくテキストを言っていない。私はrestartする必要がありますヒンディー語を正しく話すためのアプリ。android tts hindi locale

t1 = new TextToSpeech(getApplicationContext(), new TextToSpeech.OnInitListener() { 
     @Override 
     public void onInit(int status) { 
      if (status != TextToSpeech.ERROR) { 
       setVolumeControlStream(AudioManager.STREAM_MUSIC); 

      } 
     } 
    }); 

    b1.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 
      String toSpeak = ed1.getText().toString().trim(); 
      t1.speak(toSpeak, TextToSpeech.QUEUE_FLUSH, null); 

     } 
    }); 
+0

下記を参照してください。 –

+0

パラメータとしてnullを渡し、進行状況や発音リスナーを設定しないと問題が発生する可能性があります。また、話す前に、いくつかのロギングを使ってttsの現在の言語を出力してください()。 – brandall

答えて

0

ヒント使用のために以下のコードを使用してください。そのコードは私のために働く。

public class AndroidTextToSpeechActivity extends Activity implements 
    TextToSpeech.OnInitListener { 
private TextToSpeech tts; 
private Button btnSpeak; 
private EditText txtText; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    tts = new TextToSpeech(this, this); 
    btnSpeak = (Button) findViewById(R.id.btnSpeak); 

    txtText = (EditText) findViewById(R.id.txtText); 

    // button on click event 
    btnSpeak.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View arg0) { 
      speakOut(); 
     } 

    }); 
} 

@Override 
public void onDestroy() { 
    // Don't forget to shutdown! 
    if (tts != null) { 
     tts.stop(); 
     tts.shutdown(); 
    } 
    super.onDestroy(); 
} 

@Override 
public void onInit(int status) { 
    // TODO Auto-generated method stub 

    if (status == TextToSpeech.SUCCESS) { 

     int result = tts.setLanguage(new Locale("hi")); 
     if (result == TextToSpeech.LANG_MISSING_DATA 
       || result == TextToSpeech.LANG_NOT_SUPPORTED) { 
      Log.e("TTS", "Language is not supported"); 
     } else { 
      btnSpeak.setEnabled(true); 
      speakOut(); 
     } 

    } else { 
     Log.e("TTS", "Initilization Failed"); 
    } 

} 

private void speakOut() { 
    String text = txtText.getText().toString(); 
    tts.speak(text, TextToSpeech.QUEUE_FLUSH, null); 

} 
}