我正在 RPi3 上开发 Android Things SDK 的 Preview 2。尝试了录音机和媒体录音机,仍然无法捕获音频。我正在尝试将我的语音转换为文本。不支持常规语音识别。我将 USB MIC 直接连接到 RPi3 以及通过 USB 声卡连接到 RPi3 的耳机 MIC。
媒体记录器代码:
private void startRecording() {
Log.d(TAG, "startRecording....");
mRecorder = new MediaRecorder();
Log.d(TAG, "startRecording: Audio Source"+MediaRecorder.getAudioSourceMax());
mRecorder.setAudioSource(MediaRecorder.AudioSource.UNPROCESSED);
mRecorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
mRecorder.setOutputFile(mFileName);
mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
try {
mRecorder.prepare();
} catch (IOException e) {
Log.e(TAG, "prepare() failed");
}
mRecorder.start();
}
private void stopRecording() {
// stops the recording activity
if (mRecorder != null) {
mRecorder.stop();
mRecorder.release();
mRecorder = null;
}
}
清单权限:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
错误:
03-09 17:17:38.662 3970 3970 D MainActivity: onCreate
03-09 17:17:38.668 3970 3970 D MainActivity: startRecording....
03-09 17:17:38.672 3970 3970 D MainActivity: startRecording: Audio Source9
03-09 17:17:38.678 161 161 E AudioSystem: AudioSystem::getInputBufferSize failed sampleRate 8000 format 0x1 channelMask 10
03-09 17:17:38.678 161 161 E AudioRecord: AudioSystem could not query the input buffer size for sampleRate 8000, format 0x1, channelMask 0x10; status -22
03-09 17:17:38.678 161 161 E StagefrightRecorder: audio source is not initialized
03-09 17:17:38.678 3970 3970 E MediaRecorder: start failed: -2147483648
03-09 17:17:38.680 3970 3970 D AndroidRuntime: Shutting down VM
03-09 17:17:38.683 3970 3970 E AndroidRuntime: FATAL EXCEPTION: main
03-09 17:17:38.683 3970 3970 E AndroidRuntime: Process: com.example.androidthings.myproject, PID: 3970
03-09 17:17:38.683 3970 3970 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.androidthings.myproject/com.example.androidthings.myproject.MainActivity}: java.lang.RuntimeException: start failed.
03-09 17:17:38.683 3970 3970 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2646)
03-09 17:17:38.683 3970 3970 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
03-09 17:17:38.683 3970 3970 E AndroidRuntime: at android.app.ActivityThread.-wrap12(ActivityThread.java)
03-09 17:17:38.683 3970 3970 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
03-09 17:17:38.683 3970 3970 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:102)
03-09 17:17:38.683 3970 3970 E AndroidRuntime: at android.os.Looper.loop(Looper.java:154)
03-09 17:17:38.683 3970 3970 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:6077)
03-09 17:17:38.683 3970 3970 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method)
03-09 17:17:38.683 3970 3970 E AndroidRuntime: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
03-09 17:17:38.683 3970 3970 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
03-09 17:17:38.683 3970 3970 E AndroidRuntime: Caused by: java.lang.RuntimeException: start failed.
03-09 17:17:38.683 3970 3970 E AndroidRuntime: at android.media.MediaRecorder.start(Native Method)
03-09 17:17:38.683 3970 3970 E AndroidRuntime: at com.example.androidthings.myproject.MainActivity.startRecording(MainActivity.java:181)
03-09 17:17:38.683 3970 3970 E AndroidRuntime: at com.example.androidthings.myproject.MainActivity.onCreate(MainActivity.java:63)
03-09 17:17:38.683 3970 3970 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:6662)
03-09 17:17:38.683 3970 3970 E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
03-09 17:17:38.683 3970 3970 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
03-09 17:17:38.683 3970 3970 E AndroidRuntime: ... 9 more