如何在Android中录制音频时调整麦克风灵敏度 [英] How to adjust microphone sensitivity while recording audio in android
问题描述
我正在制作录音应用程序。在app中我有一个Seekbar来改变输入语音增益。
我找不到任何调整输入语音增益的方法。
I am working on a voice recording app. in app I have a Seekbar to change input voice gain. I could not found any way to adjust input voice gain.
我正在使用AudioRecord课程录制语音。
I am using AudioRecord class to record voice.
recorder = new AudioRecord(MediaRecorder.AudioSource.MIC,
RECORDER_SAMPLERATE, RECORDER_CHANNELS,
RECORDER_AUDIO_ENCODING, bufferSize);
recorder.startRecording();
我在Play商店看到了一个使用此功能的应用程序。
I have seen an app also in play store which are using this functionality.
https://play.google.com/store/apps/details?id=com.grace.microphone
推荐答案
据我所知,您不需要任何自动调整,只需手动从UI进行操作。 Android中没有内置功能,您必须手动修改数据。
As I understand you don't want any automatic adjustments, only manual from the UI. There is no built-in functionality for this in Android, instead you have to modify your data manually.
假设您使用 read(short [] audioData,int offsetInShorts,int sizeInShorts)用于阅读流。所以你应该做这样的事情:
Suppose you use read (short[] audioData, int offsetInShorts, int sizeInShorts) for reading the stream. So you should just do something like this:
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);
}
}
Math.min 如果
增益
大于1,code>用于防止溢出。
Math.min
is used to prevent overflow if gain
is greater than 1.
这篇关于如何在Android中录制音频时调整麦克风灵敏度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!