My TextToSpeechは最初の実行で正常に動作しますが、アプリケーションが「戻る」キーを使用して閉じられてから再開すると機能しません。私はのonCreateでVoiceGeneratorのインスタンスを取得Android TextToSpeech:話が失敗しました:TTSエンジンにバインドされていません
public class VoiceGenerator {
public TextToSpeech tts;
private Context context;
private String TAG = "Voice Generator";
private static VoiceGenerator instance;
private VoiceGenerator(Context context){
this.context = context;
}
public static VoiceGenerator getInstance(Context context){
if (instance == null) {
instance = new VoiceGenerator(context);
}
return instance;
}
public void initializeTTS() {
if (tts == null) {
Log.d(TAG, "initialize tts");
tts = new TextToSpeech(context, new TextToSpeech.OnInitListener() {
@Override
public void onInit(int status) {
if (status != TextToSpeech.ERROR) {
Log.d(TAG, "initialize tts success");
tts.setLanguage(...);
}
}
});
}
}
public void speak(){
tts.speak(...)
}
public void shutdown(){
if(tts != null) {
tts.stop();
tts.shutdown();
tts=null;
Log.d(TAG, "TTS Destroyed");
}
}
}
:ONSTARTで
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
voiceGenerator = VoiceGenerator.getInstance(this);
}
初期化TTS:エラーは、私はTTSを扱うためのクラスを持っているERROR
あるonInit
にTextToSpeech: speak failed: not bound to TTS engine
とstatus
です
@Override
protected void onStart(){
super.onStart();
voiceGenerator.initializeTTS();
}
そしてonDestroyでそれをシャットダウン:私が間違っているのかについて
@Override
protected void onDestroy() {
super.onDestroy();
voiceGenerator.shutdown();
}
任意のアイデア?
問題はこれで解決しないようにステータスがERRORであることです。 – suue