Change Android Audio Record Default input Source

2019-06-23 15:34发布

问题:

I am currently writing an app that calls for the recording and real time processing of audio data. For this, I am using the AudioRecord class. This works all well and good, except the default setting for recording audio on my primary testing device, a galaxy nexus, is to record from the back speaker. I am assuming most phones default record source will be the back, or bottom microphones, because when you are using the phone to call, your mouth is near the bottom.

However, my app requires that I record from the speaker on the front of the phone, and so I was hoping someone could help me with how to change the AudioRecord input source programmatically. I have searched extensively for the answer to this.

Some things I have considered are:

  • Using the AudioManager Class and turning on the speaker phone, such as:

    AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
    am.setSpeakerphoneOn(true);

  • Changing the AudioSource parameter in the construction of my AudioRecord object:

    AudioRecord ar = new AudioRecord(AudioSource.????, ..., ..., ..., ...);

  • I have found that the API's are not too specific about which AudioSource formats are which, so I was wondering if anyone else has struggled with this issue and could point me in the right direction.

    Thanks in advance,

    回答1:

    Android does not currently support call recording, so I believe you can't change it to record from the earpiece. You shouldn't really need to however, the Mic at the bottom of the phone should be able to record things to the full capacity you need. To set the AudioRecord to the mic, just do:

    AudioRecord ar = new AudioRecord(AudioSource.MIC, ..., ..., ..., ...);
    

    This will give you the best recording quality.