我正在研究RPi3上Android Things的SDK的預覽版2。嘗試錄音機以及媒體錄音機,仍然無法獲取音頻捕獲。我正在試圖將我的演講轉換爲文字。不支持常規SpeechRecognition。我有USB MIC直接連接到RPi3以及通過USB聲卡連接到RPi3的耳機MIC。如何在Android上錄製語音事物
MediaRecorder代碼:
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
這給所有導致NULL的組合導致了不良的緩衝區大小AudioRecorder –