Android AudioRecord forcing another stream to MIC audio source

前端 未结 2 433
孤独总比滥情好
孤独总比滥情好 2020-12-22 19:20

Update 3: I have partnered with another developer and we seem to found somebody who can do this for a large sum of money. They have sent us a test apk and i

相关标签:
2条回答
  • 2020-12-22 19:52

    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

    0 讨论(0)
  • 2020-12-22 19:54

    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

    0 讨论(0)
提交回复
热议问题