问题描述
由于某些原因,我不能调用包含PhoneCallListener从onutteranceCompleted的方法。有没有错误信息,它只是似乎停止执行脚本。我已经添加了一些日志和它获取到这里的日志中setUpPhone与PhoneCallListener。如果没有PhoneCallListener它会得到最后的日志手机设置。下面是我是如何实现它例如code。
@覆盖
公共无效的OnInit(INT状态)
{
如果(状态== TextToSpeech.SUCCESS)
{
tts.setOnUtteranceCompletedListener(本);
INT结果= tts.setLanguage(Locale.US); 如果(结果== || TextToSpeech.LANG_MISSING_DATA结果== TextToSpeech.LANG_NOT_SUPPORTED)
{
//不支持语言
}
其他
{
讲出();
}
}}私人无效SPEAKOUT()
{
HashMap的<字符串,字符串> myHashAlarm =新的HashMap<字符串,字符串>();
myHashAlarm.put(TextToSpeech.Engine.KEY_PARAM_STREAM,将String.valueOf(AudioManager.STREAM_ALARM));
myHashAlarm.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID,文本到语音);
tts.speak(等等等等,TextToSpeech.QUEUE_FLUSH,myHashAlarm);
}@覆盖
公共无效的onDestroy()
{
如果(TTS!= NULL)
{
tts.stop();
tts.shutdown();
} super.onDestroy();
}公共无效onUtteranceCompleted(字符串utteranceId)
{
Log.i(TEST,utteranceId);
setUpPhone();
Log.i(TEST,手机设置); //这是从来没有达到
}私人无效setUpPhone()
{
Log.i(TEST,这里); PhoneCallListener phoneListener =新PhoneCallListener(); //如果我删除此行,日志手机设置显示器。
}
我不知道为什么PhoneCallListener停止执行,但是我通过投入解决了这个phoneListener =新PhoneCallListener();在onCreate方法。
For some reason I can't call a method that contains PhoneCallListener from onutteranceCompleted. There are no error messages, it just seems to stop executing the script. I've added some Logs and it gets to the "here" log in setUpPhone with PhoneCallListener. Without PhoneCallListener it will get to the final log "phone set up". Here is example code of how I have it implemented.
@Override
public void onInit(int status)
{
if(status == TextToSpeech.SUCCESS)
{
tts.setOnUtteranceCompletedListener(this);
int result = tts.setLanguage(Locale.US);
if(result == TextToSpeech.LANG_MISSING_DATA || result == TextToSpeech.LANG_NOT_SUPPORTED)
{
//Language not supported
}
else
{
speakOut();
}
}
}
private void speakOut()
{
HashMap<String, String> myHashAlarm = new HashMap<String, String>();
myHashAlarm.put(TextToSpeech.Engine.KEY_PARAM_STREAM, String.valueOf(AudioManager.STREAM_ALARM));
myHashAlarm.put(TextToSpeech.Engine.KEY_PARAM_UTTERANCE_ID, "Text to Speech");
tts.speak("blah blah", TextToSpeech.QUEUE_FLUSH, myHashAlarm);
}
@Override
public void onDestroy()
{
if(tts != null)
{
tts.stop();
tts.shutdown();
}
super.onDestroy();
}
public void onUtteranceCompleted(String utteranceId)
{
Log.i("TEST", utteranceId);
setUpPhone();
Log.i("TEST", "phone set up"); //this is never reached
}
private void setUpPhone()
{
Log.i("TEST", "here");
PhoneCallListener phoneListener = new PhoneCallListener(); //If I remove this line, the log "phone set up" displays.
}
I don't know why PhoneCallListener stops execution, however I solved this by putting "phoneListener = new PhoneCallListener();" in the onCreate method.
这篇关于onUtteranceCompleted将不允许PhoneCallListener的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!