我正试图从麦克风中捕获音频而不管是什么缓冲区
size {bufferSizeInBytes
)我在AudioRecord
的构造时间设置,何时
我做AudioRecord.read
我总是得到8192
字节的音频数据(128
女士)。我希望AudioRecord.read
能够阅读40ms
数据
(2560 bytes
)。我能找到的唯一可用的示例代码是Sipdroid
(RtpStreamSender.java
)我还没试过。
这是我的代码的相关部分:
public void run()
{
running = true;
android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_URG ENT_AUDIO);
try {
frameSize = AudioRecord.getMinBufferSize(samplingRate,
AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT);
Log.i(TAG, "trying to capture " + String.format("%d", frameSize) + " bytes");
record = new AudioRecord(MediaRecorder.AudioSource.MIC, samplingRate,
AudioFormat.CHANNEL_CONFIGURATION_MONO, AudioFormat.ENCODING_PCM_16BIT, frameSize);
record.startRecording();
byte[] buffer = new byte[frameSize];
while (running)
{
record.read(buffer, 0, frameSize);
Log.i(TAG, "Captured " + String.format("%d", frameSize) + " bytes of audio");
}
record.stop();
record.release();
} catch (Throwable t) {
Log.e(TAG, "Failed to capture audio");
}
}
我的问题/评论是: