Android AudioRecord forcing another stream to MIC audio source Android AudioRecord forcing another stream to MIC audio source android android

Android AudioRecord forcing another stream to MIC audio source


Me and my partner were able to purchase what we were looking for. We were on right path, you set keyValuePairs on the native side.

Unfortunately I cannot publish the source because of the licensing restrictions from the company we had it written for us


Your findings are interesting. I have worked on a few small projects involving the AudioRecord API. Hopefully, the following will help:

Say you want to setup an AudioRecord instance so that you can record in 16-bit mono at 16kHz. You can achieve this by creating a class with a few helper methods, like the following:

public class AudioRecordTool {        private final int minBufferSize;        private boolean doRecord = false;        private final AudioRecord audioRecord;        public AudioRecordTool() {            minBufferSize = AudioTrack.getMinBufferSize(16000,                    AudioFormat.CHANNEL_OUT_MONO,                    AudioFormat.ENCODING_PCM_16BIT);            audioRecord = new AudioRecord(                    MediaRecorder.AudioSource.VOICE_COMMUNICATION,                    16000,                    AudioFormat.CHANNEL_IN_MONO,                    AudioFormat.ENCODING_PCM_16BIT,                    minBufferSize * 2);        }        public void writeAudioToStream(OutputStream audioStream) {            doRecord = true; //Will dictate if we are recording.            audioRecord.startRecording();            byte[] buffer = new byte[minBufferSize * 2];            while (doRecord) {                int bytesWritten = audioRecord.read(buffer, 0, buffer.length);                try {                    audioStream.write(buffer, 0, bytesWritten);                } catch (IOException e) {                    //You can log if you like, or simply ignore it                   stopRecording();                }            }            //cleanup            audioRecord.stop();            audioRecord.release();        }        public void stopRecording() {            doRecord = false;        }    }

I am guessing you will need to keep the same permissions in place, since Marshmallow users are the only ones that grant us access to certain permissions if not almost all of the cool ones.

Try implementing the class and let us know how it went, also i'm leaving some extra references in case you need more research.

Good luck.

AudioRecord API

AudioCaputre API

MediaRecorder API