2017-09-07 53 views
1

我遇到Google雲語音問題。我無法暫停Google Cloud Speech,暫停我正在關閉SpeechRecognizer的識別功能,當我再次需要時,我再次啓動它。但這樣,Stopping需要很多時間來停止,我必須在後臺線程中運行。有時它會及時停止,但並非總是如此。對於我在主線程中使用的幾天,我沒有任何問題,但現在它開始跳過幀,所以我把它移動了。我需要它立即停止,因爲停止後跟着語音到文本,並且如果我等到識別停止,那麼即使我將它移動到後臺線程上,流程也會顯得遲緩。 我使用的代碼從他們的樣品,啓動和停止它:Google雲語音暫停

private void stopVoiceRecorder() { 
    mNotifyForVoiceEnd.start(); 
    if (mVoiceRecorder != null) { 
     mVoiceRecorder.stop(); 
    } 
    isListening = false; 
    runOnUiThread(new Runnable() { 
     @Override 
     public void run() { 
      appBar.setBackgroundColor(ContextCompat.getColor(MainActivity.this, R.color.primary)); 

     } 
    }); 
} 

開始承認:

private void startVoiceRecorder() { 
    mNotifyForVoiceStart.start(); 
    if (mVoiceRecorder != null) { 
     mVoiceRecorder.stop(); 
     mVoiceRecorder = null; 
    } 
    mVoiceRecorder = new VoiceRecorder(mVoiceCallback); 
    mVoiceRecorder.start(); 
    isListening = true; 
    runOnUiThread(new Runnable() { 
     @Override 
     public void run() { 
      appBar.setBackgroundColor(ContextCompat.getColor(MainActivity.this, R.color.tab_not_hearing)); 
     } 
    }); 
} 

我用TraceView和做大量的工作問題是

mVoiceRecorder.stop(); 

和代碼.stop()

public void stop() { 
    synchronized (mLock) { 
     if (mThread != null) { 
      mThread.interrupt(); 
      mThread = null; 
     } 

     dismiss(); 
     if (mAudioRecord != null) { 
      mAudioRecord.stop(); 
     } 

    } 
} 

有沒有辦法暫停識別?

回答

1

我找到了解決辦法:

// Simply delete synchronized (mLock) 

    public void stop() { 

    if (mThread != null) { 
     mThread.interrupt(); 
     mThread = null; 
    } 

    dismiss(); 
    if (mAudioRecord != null) { 
     mAudioRecord.stop(); 
    } 

}