我有一个按钮,当按下时,我想玩一个正确的'使用文本到语音之前的声音。然而,虽然文本到语音在“正确”之前开始。声音播放完毕,两个声音重叠。一旦“纠正”错误,我该如何开始发送文字?声音播放完了?任何帮助表示赞赏。非常感谢!!
public void onClick(View view){
Button btn = (Button) view;
TextView tv = (TextView) findViewById(R.id.animal_text);
textViewString = tv.getText().toString();
final MediaPlayer mp = MediaPlayer.create(this, R.raw.correct);
if (btn.getText().equals(textViewString)) {
mp.start();
Resources res = getResources();
String[] myString = res.getStringArray(R.array.englishAnimalArray);
String q = myString[r_generator.nextInt(myString.length)];
tv.setText(q);
textViewString = tv.getText().toString();
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.HONEYCOMB) {
tts.speak(textViewString, TextToSpeech.QUEUE_FLUSH, null);
} else {
tts.speak(textViewString, TextToSpeech.QUEUE_FLUSH, null, null);
}
}
答案 0 :(得分:0)
您是否看过API指南? Callback setOnCompletionListener(OnCompletionListener)(https://developer.android.com/reference/android/media/MediaPlayer.html#Callbacks)怎么样?
mp.setOnCompletionListener(new OnCompletionListener(){
/* Implement the needed functionality */
});