如何在Android中录制音频时调整麦克风灵敏度

7 java android audiorecord android-audiorecord

我正在制作一个录音应用程序.在app中我有一个Seekbar来改变输入语音增益.我找不到任何调整输入语音增益的方法.

我正在使用AudioRecord类来录制语音.

 recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,
            RECORDER_SAMPLERATE, RECORDER_CHANNELS,
            RECORDER_AUDIO_ENCODING, bufferSize);

    recorder.startRecording();
Run Code Online (Sandbox Code Playgroud)

我在Play商店看到了一个使用此功能的应用程序.

https://play.google.com/store/apps/details?id=com.grace.microphone

Ant*_*vin 14

据我了解,您不希望任何自动调整,只需从UI手动.Android中没有内置功能,您必须手动修改数据.

假设您使用read(short [] audioData,int offsetInShorts,int sizeInShorts)来读取流.所以你应该做这样的事情:

float gain = getGain(); // taken from the UI control, perhaps in range from 0.0 to 2.0
int numRead = read(audioData, 0, SIZE);
if (numRead > 0) {
    for (int i = 0; i < numRead; ++i) {
        audioData[i] = (short)Math.min((int)(audioData[i] * gain), (int)Short.MAX_VALUE);
    }
}
Run Code Online (Sandbox Code Playgroud)

Math.min用于防止溢出,如果gain大于1.