我正在试验安卓的录音和回放。是否有方法枚举设备上可用的音频参数?
现在,当我传递硬件(或模拟器)不喜欢的参数组合时,我只会得到一个错误。所以我不得不“猜”一下:
int bufferSize;
int sampleRate;
// does the audio hardware do 44 kHz?
sampleRate = 44100;
bufferSize = AudioRecord.getMinBufferSize(sampleRate,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT);
if (bufferSize != AudioTrack.ERROR_BAD_VALUE) {
// Nope, how about 22 kHz?
sampleRate = 22050;
}
bufferSize = AudioRecord.getMinBufferSize(sampleRate,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT);
if (bufferSize != AudioTrack.ERROR_BAD_VALUE) {
...
当然还有更好的办法!
This chart
表示
只有
支持的音频输入采样率是8kHz?对吗?