Android - 语音识别和保存音频文件 - 在某些设备上不工作

标签 android voice-recognition google-speech-api google-voice

我有语音识别和保存音频文件的工作解决方案,但代码仅适用于某些设备。

我试过在几台设备上运行这段代码。似乎此解决方案适用于 android 5.0,但不适用于更高版本。

我正在使用 Intent 类来做到这一点:

System.out.println("startVoiceInput");
    Intent intent = new Intent(RecognizerIntent.ACTION_RECOGNIZE_SPEECH);
                intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE_MODEL, RecognizerIntent.LANGUAGE_MODEL_FREE_FORM);
                intent.putExtra(RecognizerIntent.EXTRA_LANGUAGE, Locale.getDefault());
                intent.putExtra(RecognizerIntent.EXTRA_PROMPT, "Hello, How can I help you?");
                intent.putExtra("android.speech.extra.GET_AUDIO_FORMAT", "audio/AMR");
                intent.putExtra("android.speech.extra.GET_AUDIO", true);
                try {
                    startActivityForResult(intent, REQ_CODE_SPEECH_INPUT);
                } catch (ActivityNotFoundException a) {
                    a.printStackTrace();
                }

识别本身适用于所有设备(没有这些行:

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

)。

但是对于捕获音频流以将其保存在设备上所必需的那几行,谷歌弹出窗口不会出现。我没有收到任何错误,但是这个日志:

D/ViewRootImpl@e232f4[RecordingActivity]: ViewPostIme pointer 0
D/ViewRootImpl@e232f4[RecordingActivity]: ViewPostIme pointer 1
I/System.out: startVoiceInput
D/ViewRootImpl@e232f4[RecordingActivity]: MSG_WINDOW_FOCUS_CHANGED 0
I/System.out: onActivityResult
D/ViewRootImpl@e232f4[RecordingActivity]: Relayout returned: old=[0,0][1080,1920] new=[0,0][1080,1920] result=0x1 surface={valid=true 527892242432} changed=false
   MSG_WINDOW_FOCUS_CHANGED 1
V/InputMethodManager: Starting input: tba=android.view.inputmethod.EditorInfo@4dc5d3e nm : com.example.acces ic=null
I/InputMethodManager: startInputInner - mService.startInputOrWindowGainedFocus

最佳答案

Google Keep 仍然使用这些 secret 参数。您可以按照说明查看here .所以它应该可以工作。

我在我的应用程序中检查过它。如果您的应用程序没有 RECORD_AUDIO 权限,则不会出现 Google 弹出窗口。如果您向 AndroidManifest.xml 添加 RECORD_AUDIO 权限,则解决方案描述 here有效。

关于Android - 语音识别和保存音频文件 - 在某些设备上不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55457053/

相关文章:

keyboard - 用语音控制代替键盘

python - 当语音识别结果不是预期时打印消息

ios - 有没有办法使用 iOS/Siri 语音转文本功能将语音界面添加到应用程序中?

speech-recognition - 如何使用 Codename One 中的 Google Speech API?

javascript - 如何防止 NodeJS 中的异步 - 等待任务 a 完成后再启动任务 b

java - 动态向 Fragment 添加按钮

java - Android 2.2 SurfaceView#onTouchEvent() 每个事件被调用两次

android - SQLiteOpenHelper onCreate()/onUpgrade() 什么时候运行?

android - Droid 上的屏幕键盘问题

google-speech-api - 谷歌语音转文本api/谷歌云语音解决方案中的用户数据隐私