0
當我的文本到語音正在啓動時,我需要啓動一個可繪製動畫,當文本到語音結束時停止該動畫,但我無法停止動畫。當文本到語音結束時做些什麼
代碼:
tts = new TextToSpeech(this, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status == TextToSpeech.SUCCESS) {
int result = tts.setLanguage(Locale.US);
if (result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED) {
Log.e("TTS", "This Language is not supported");
}
} else {
Log.e("TTS", "Initilization Failed!");
}
}
});
private void speak(String text){
animation.start();
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null, null);
}else{
tts.speak(text, TextToSpeech.QUEUE_FLUSH, null);
}
}
,在這裏我animationdrawable XML
<animation-list xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/selected" android:oneshot="false" >
<item android:drawable="@drawable/face_1a_mini" android:duration="250" />
<item android:drawable="@drawable/face_1b_mini" android:duration="250" />
<item android:drawable="@drawable/face_1c_mini" android:duration="250" />
<item android:drawable="@drawable/face_1d_mini" android:duration="250" />
</animation-list>
您好,歡迎堆棧溢出,請花時間去通過[歡迎參觀(https://stackoverflow.com/tour)知道自己的方式在這裏(也賺你的第一個徽章),閱讀如何創建[Minimal,Complete和Verifiable示例](https://stackoverflow.com/help/mcve),並檢查[如何提出好問題](https://stackoverflow.com/help/)如何問),這樣你可以增加獲得反饋和有用答案的機會。 – DarkCygnus
[如何知道TTS何時完成?]的可能重複(https://stackoverflow.com/questions/4658376/how-to-know-when-tts-is-finished) –