【问题标题】:Google cloud speech pause谷歌云语音暂停
【发布时间】:2017-09-07 07:33:03
【问题描述】:

我在使用 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();
        }

    }
}

有什么办法可以暂停识别吗?

【问题讨论】:

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


    【解决方案1】:

    我找到了解决方案:

     // Simply delete   synchronized (mLock)
    
       public void stop() {
    
        if (mThread != null) {
            mThread.interrupt();
            mThread = null;
        }
    
        dismiss();
        if (mAudioRecord != null) {
            mAudioRecord.stop();
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 2017-07-11
      • 1970-01-01
      • 2023-04-09
      • 1970-01-01
      • 2017-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多