I have an application where I want to record someone's speech during a
phone call. When I use the MediaRecorder object with VOICE_COMMUNICATION as
input, the echo cancelation works just fine. However, when I use an
AudioRecord, it does not work. I tried chosing VOICE_COMMUNICATION as input
for the AudioRecord, as well as normal MIC input and manually attached the
AEC (AcousticEchoCanceler) to the record.
*THIS WORKS:*
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_COMMUNICATION);
recorder.setOutputFormat(MediaRecorder.OutputFormat.AAC_ADTS);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
recorder.setAudioEncodingBitRate(16000);
recorder.setAudioSamplingRate(44100);
*THIS DOES NOT WORK:*
OutputStream outputStream = new FileOutputStream(filePcm);BufferedOutputStream
bufferedOutputStream = new BufferedOutputStream(outputStream);DataOutputStream
dataOutputStream = new DataOutputStream(bufferedOutputStream);
int minBufferSize = AudioRecord.getMinBufferSize(SAMPLE_RATE_HZ,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT);
short[] audioData = new short[minBufferSize];
AudioRecord audioRecord = new AudioRecord(MediaRecorder.AudioSource.MIC,
44100,
AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT,
minBufferSize);AcousticEchoCanceler canceler =
AcousticEchoCanceler.create(audioRecord.getAudioSessionId());NoiseSuppressor
suppressor = NoiseSuppressor.create(audioRecord.getAudioSessionId());if
(suppressor != null) {
suppressor.setEnabled(true);}
if (canceler != null) {
canceler.setEnabled(true);}
audioRecord.startRecording();
while (recording) {
int numberOfShort = audioRecord.read(audioData, 0, minBufferSize);
for (int i = 0; i < numberOfShort; i++) {
dataOutputStream.writeShort(audioData[i]);
}}
audioRecord.stop();
Can anybody tell me what I am doing wrong?
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/b55b6787-35b5-4547-8800-0d034673af01%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.