从语音识别意图中获取音频

时间:2017-10-06 11:12:26

标签: android audio speech-recognition speech-to-text recognizer-intent

我几乎每个链接都会在onActivityResult() RecognizerIntent中获取音频数据。

1. Get URI of saved audio in OnResults(Bundle result) in Speech RecognitionListener android
2. record/save audio from voice recognition intent

我遵循相同的方法,我的代码几乎相同。但我从data.getData()回来了 null ; 非常感谢任何帮助。

这是我的代码:

    private void startVoiceRecognitionActivity() {
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);

    String language = Locale.US.toString();
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, language);
    intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, language);

    intent.putExtra("android.speech.extra.GET_AUDIO_FORMAT", "audio/AMR");
    intent.putExtra("android.speech.extra.GET_AUDIO", true);

    startActivityForResult(intent, REQUEST_CODE);
}

   @Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == REQUEST_CODE && resultCode == RESULT_OK) {
        Bundle bundle = data.getExtras();

        // This part works fine.
        ArrayList<String> matches = bundle.getStringArrayList(RecognizerIntent.EXTRA_RESULTS);

        // But audioUri is always null !!!
        Uri audioUri = data.getData();
        ...
}

在我的AndroidManifest.xml文件中,我有

<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />


提前谢谢。

0 个答案:

没有答案