谷歌云语音暂停

时间:2017-09-07 07:33:04

标签: java android speech-recognition google-cloud-speech

我遇到了Google Cloud Speech问题。我无法暂停谷歌云语音,暂停识别我正在关闭SpeechRecognizer,当我再次需要它时,我再次启动它。但是这样,停止需要很长时间才能停止,我必须在后台线程中运行。有时它会及时停止,但并非总是如此。我在主线程上使用的几天我没有遇到任何问题,但现在它开始跳帧,所以我移动它。我需要它立即停止,因为在停止之后是语音到文本,如果我等到识别停止,即使我在后台线程上移动它,流也会看起来很迟。 我正在使用他们样本中的代码来启动和停止它:

    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 个答案:

答案 0 :(得分:1)

我找到了解决方案:

 // Simply delete   synchronized (mLock)

   public void stop() {

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

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

}