bounty将在3天内到期。回答此问题可获得+50声望奖励。Qamar正在寻找来自信誉良好的来源的**答案 *。
问题是我们正在使用HDMI捕获设备来渲染帧和音频。该设备使用UAC协议,该协议已注册为输入音频设备并被选为语音引擎的默认输入源。我们希望将语音引擎的输入音频源更改为使用内置底部麦克风或背面CAMCORDER麦克风。
互联网上的资源有限。相关问题很少
- Android Speech Recognition Custom Audio Source的
- Android speech recognizing and audio recording in the same time的
我们尝试了以下代码。下面的解决方案是受Github.com/KieronQuinn/AmbientMusicMod启发的
此代码静音的语音引擎的源代码,但不工作!
val SAMPLE_RATE = 44100
val CHANNEL_CONFIG = AudioFormat.CHANNEL_IN_MONO
val AUDIO_FORMAT = AudioFormat.ENCODING_PCM_16BIT
// val bufferSize = AudioRecord.getMinBufferSize(SAMPLE_RATE, CHANNEL_CONFIG, AUDIO_FORMAT)
val audioRecord = AudioRecord.Builder()
.setAudioSource(MediaRecorder.AudioSource.CAMCORDER)
.setAudioFormat(AudioFormat.Builder()
.setEncoding(AUDIO_FORMAT)
.setSampleRate(SAMPLE_RATE)
.setChannelMask(CHANNEL_CONFIG)
.build())
// .setBufferSizeInBytes(bufferSize)
.build()
val fileDescriptors = ParcelFileDescriptor.createReliablePipe()
val clientRead = fileDescriptors[0]
audioRecord.startRecording()
Thread {
try {
// datagramSocket.send(datagramPacket)
val audioSink = fileDescriptors[1]
ParcelFileDescriptor.AutoCloseOutputStream(audioSink).use { fos ->
val buffer = ByteArray(audioRecord.bufferSizeInFrames)
while (isListening) {
val bytesRead =
audioRecord.read(buffer, 0, buffer.size, AudioRecord.READ_BLOCKING)
if (bytesRead > 0) {
// datagramSocket.send(datagramPacket)
fos.write(buffer)
}
}
}
} catch (e: Exception) {
e.printStackTrace()
}
audioRecord.stop()
audioRecord.release()
}.start()
speechIntent.putExtra("android.speech.extra.AUDIO_SOURCE", clientRead)
speechIntent.putExtra("android.speech.extra.AUDIO_SOURCE_ENCODING", AUDIO_FORMAT)
speechIntent.putExtra("android.speech.extra.AUDIO_SOURCE_SAMPLING_RATE", SAMPLE_RATE)
speechIntent.putExtra("android.speech.extra.AUDIO_SOURCE_CHANNEL_COUNT", CHANNEL_CONFIG)
speechRecognizer.startListening(speechIntent)
字符串
安卓13谷歌语音识别v20230807 Google Groups Thread
或者disable automatic routing to USB audio peripherals
编程的任何解决方法!?
1条答案
按热度按时间lndjwyie1#
您的应用应具有授予的WRITE_SECURE_SETTINGS权限。然后调用
Settings.Secure.putInt(context.getContentResolver(), "usb_audio_automatic_routing_disabled", 1)
。- Irfan f我们可以使用以下ADB命令授予WRITE_SECURE_SETTINGS权限。
adb shell pm grant app.package.name android.permission.WRITE_SECURE_SETTINGS
个阅读更多here (USB-audio)
旁注
目前,这是解决我们问题的唯一办法。我希望Google/AOSP会考虑这个案例。