首页 文章

Android在进行语音识别时录制音频

提问于
浏览
3

我正在使用Android上的第三方 Cloud 服务进行语音识别,并且它适用于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);

同时,我想用不同的音频设置录制音频,如频率, Channels ,音频格式等 . 然后我会不断分析这个音频缓冲区 . 我使用AudioRecord来达到目的 . 这只适用于我关闭语音识别 .

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

E/AudioRecord: start() status -38

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

1 回答

相关问题