Android,如何初始化录音机?

时间:2012-01-28 19:54:27

标签: android audio-recording audio

我创建了AudioMeter课程,我在其承包商中编写了以下代码:

public AudioMeter(){
        channel_config = AudioFormat.CHANNEL_CONFIGURATION_STEREO;//And also Mono
        format = AudioFormat.ENCODING_PCM_16BIT;
        sampleRate = AudioTrack.getNativeOutputSampleRate(AudioManager.STREAM_SYSTEM); //8000
        bufferSize = AudioRecord.getMinBufferSize(sampleRate, channel_config, format);

        recorder = new AudioRecord(MediaRecorder.AudioSource.MIC, sampleRate, channel_config, format, bufferSize);

        audioBuffer = new short[bufferSize];

        Log.i("AudioMeter", "Created successfully.");
    } 

但是,当我运行模拟器时,它说 01-29 03:47:07.418: E/AudioRecord(432): Unsupported configuration: sampleRate 44100, format 1, channelCount 2" 我已将“Audio Recording Support”和“Audio Playback Support”添加到模拟器中。

任何帮助都会非常感激,因为我现在已经查看了这段代码了一段时间了!

1 个答案:

答案 0 :(得分:4)

模拟器不支持CHANNEL_CONFIGURATION_STEREO& sampleRate =(11025,16000,22050和44100),如果你想成功运行,那么使用CHANNEL_CONFIGURATION_MONO& SampleRate = 8000(每秒仅支持8000个样本)。