【发布时间】:2024-01-13 07:17:01
【问题描述】:
我有语音识别和保存音频文件的有效解决方案,但该代码仅适用于某些设备。
我曾尝试在少数设备上运行此代码。该解决方案似乎适用于 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
【问题讨论】:
-
所以您使用了两个甚至不是 RecognizerIntent 的一部分的附加功能(因此在任何方面都不是官方的)并且只是希望它们能工作?这真的不会奏效。如果手机使用的是旧版本,则无法使用。如果手机使用谷歌以外的语音识别服务,它就无法工作(我知道很多人曾经使用过 Nuance)。除非您控制将响应它的应用程序,否则不要依赖非标准的附加功能来工作。
-
我在*上找到了这种方法,所以......无论如何,你知道其他解决方案吗?我还没有找到任何“标准”方式来识别语音输入,并将该输入保存为音频文件。
-
没有。这只是你无法在所有设备上获得的功能,有点担心你自己的识别器
标签: android voice-recognition google-speech-api google-voice