我正在尝试通过以下代码从麦克风读取原始数据:
short buffer[] = new short[AudioRecord.getMinBufferSize(8000,
AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT)];
Log.d("O_o",""+buffer.length);
AudioRecord rec = new AudioRecord(
MediaRecorder.AudioSource.MIC, 8000,
AudioFormat.CHANNEL_IN_MONO,
AudioFormat.ENCODING_PCM_16BIT, buffer.length);
rec.startRecording();
int read = rec.read(buffer, 0, buffer.length);
for (int i = 0; i < read; i++) {
Log.d("O_o",i+" "+buffer[i]);
}
rec.stop();
rec.release();
但缓冲区总是充满 257 个值。怎么了 ?
UDP:看起来像我的初始值。在循环中调用 read() 会导致正常值。