【问题标题】:Android record audio while doing speech recognitionAndroid 在进行语音识别时录制音频
【发布时间】:2017-02-07 11:13:20
【问题描述】:

我正在使用 Android 上的第三方云服务进行语音识别,它与 Android API SpeechRecognizer 配合得很好。代码如下:

    Intent recognizerIntent =
            new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL,
            RecognizerIntent.LANGUAGE_MODEL_WEB_SEARCH);

    // accept partial results if they come
    recognizerIntent.putExtra(RecognizerIntent.EXTRA_PARTIAL_RESULTS, true);

    //need to have a calling package for it to work
    if (!recognizerIntent.hasExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE)) {
        recognizerIntent.putExtra(RecognizerIntent.EXTRA_CALLING_PACKAGE, "com.example.speechrecognition");
    }
    recognizer = SpeechRecognizer.createSpeechRecognizer(context);
    recognizer.setRecognitionListener(this);
    recognizer.startListening(recognizerIntent);

同时,我想录制不同音频设置的音频,比如频率、频道、音频格式等。然后我会不断分析这个音频缓冲区。我为此目的使用 AudioRecord。只有我关闭语音识别才能正常工作。

如果我同时录制音频和语音识别,则会发生错误。

E/AudioRecord: start() status -38

如何实现这种功能,我也试过原生音频-SLRecordItf,也不行。

【问题讨论】:

  • 由于android策略,同时只有一个应用程序可以访问麦克风api。
  • 有没有机会做到这一点?
  • 也许你应该找到一些可以处理声音字节而不是麦克风的语音识别器。
  • 这可能是由于同时使用了手机的音频输入硬件。语音识别器和录音机都使用相同的硬件进行收听。如果一个当前正在使用硬件,另一个可能无法使用它。

标签: android speech-recognition audio-recording


【解决方案1】:

正如 cmets 所述,一次只允许/可能访问一个麦克风。

对于SpeechRecognizer,附加的RecognitionListener有一个onBufferReceived(byte[] buffer)的回调,但不幸的是,谷歌的原生识别服务并没有为此提供任何音频数据,非常令人沮丧。

您唯一的选择是使用外部服务,该服务不是免费的。 Google 的新 Cloud Speech API 有一个 Android example

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2022-08-18
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-19
  • 2015-09-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多