Android 在进行语音识别时录制音频
Android record audio while doing speech recognition
我正在 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
如何实现这种功能,我也试过native audio - SLRecordItf,也不行。
如评论所述,一次只能访问一个麦克风 permitted/possible。
对于 SpeechRecognizer the attached RecognitionListener has a callback of onBufferReceived(byte[] buffer) 但不幸的是,Google 的本地识别服务不为此提供任何音频数据,这非常令人沮丧。
您唯一的选择是使用外部服务,该服务不是免费的。 Google 的新 Cloud Speech API has an Android example.
我正在 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
如何实现这种功能,我也试过native audio - SLRecordItf,也不行。
如评论所述,一次只能访问一个麦克风 permitted/possible。
对于 SpeechRecognizer the attached RecognitionListener has a callback of onBufferReceived(byte[] buffer) 但不幸的是,Google 的本地识别服务不为此提供任何音频数据,这非常令人沮丧。
您唯一的选择是使用外部服务,该服务不是免费的。 Google 的新 Cloud Speech API has an Android example.