0
我試圖緩衝音頻數據來分析分貝級別。Android AudioRecord無法找到工作配置
我使用AudioRecord類,因爲它允許從緩衝區中立即處理數據而不將它們存儲在文件中。
我現在用的是
<uses-permission android:name="ANDROID.PERMISSION.RECORD_AUDIO" />
許可。 編輯:這是錯誤的!
我與
Intent intent = new Intent(this, Audio2.class);
startService(intent);
服務調用期間onStartCommand(...)
findAudioRecord()
啓動它從我的onStart()
主要活動相關的服務。
private int[] sampleRates = new int[] { 44_100, 22_050, 11_025, 8_000 };
private short[] audioFormats = new short[] { AudioFormat.ENCODING_PCM_16BIT, AudioFormat.ENCODING_PCM_8BIT };
private short[] channelConfigs = new short[] { AudioFormat.CHANNEL_IN_MONO, AudioFormat.CHANNEL_IN_STEREO };
public AudioRecord findAudioRecord() {
for (int rate : sampleRates){
for (short audioFormat : audioFormats){
for (short channelConfig : channelConfigs){
try {
Log.d(TAG, "Attempting rate " + rate + "Hz, " + audioFormat + " bits, channel: " + channelConfig);
bufferSize = AudioRecord.getMinBufferSize(rate, channelConfig, audioFormat);
if (bufferSize != AudioRecord.ERROR_BAD_VALUE) {
AudioRecord recorder = new AudioRecord(MediaRecorder.AudioSource.DEFAULT, rate, channelConfig, audioFormat, bufferSize*10);
if (recorder.getState() == AudioRecord.STATE_INITIALIZED) {
return recorder;
} else {
recorder.release();
}
}
} catch (Exception e) {
Log.e(TAG, rate + "Exception, keep trying.",e);
}
}
}
}
Log.wtf(TAG, "No working configuration found!");
return null;
}
這總是返回null。我收到錯誤:
E/AudioRecord﹕ AudioFlinger could not create record track, status: -1
E/AudioRecord-JNI﹕ Error creating AudioRecord instance: initialization check failed.
E/AudioRecord-Java﹕ android.media.AudioRecord Error code -20 when initializing native AudioRecord object.
我正在使用Samsung Galaxy S4。
什麼我都沒有成功嘗試:
- 重新啓動裝置多次
- 試圖在一個GT-S6790N
- 嘗試了一個模擬的設備上
- AudioRecord object not initializing嘗試一切在這個崗位(以及任何形式的相關帖子)
製造一個問題:https://code.google.com/p/android/issues/detail?id=176076 –