0

出于某种原因,我无法从 onutteranceCompleted 调用包含 PhoneCallListener 的方法。没有错误消息,它似乎只是停止执行脚本。我添加了一些日志,它通过 PhoneCallListener 进入 setUpPhone 中的“这里”日志。如果没有 PhoneCallListener,它将进入最终日志“电话设置”。这是我如何实现它的示例代码。

@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.
}
4

1 回答 1

0

我不知道为什么 PhoneCallListener 停止执行,但是我通过输入“phoneListener = new PhoneCallListener();”解决了这个问题 在 onCreate 方法中。

于 2013-11-30T01:18:20.370 回答