Audio recorded from microphone is muted during the

2019-04-14 17:38发布

问题:

I am trying to build application which records audio from the microphone for the later processing.

Everything works fairly well, except the following problem: During the voice call (in and out) the recorded file gets no audio data, it contains just NULLs.

I am using AudioRecorder and MediaRecorder, both have the same problem. The question is if this is normal API behavior or I am missing something?

Here some additional info: Permissions:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />

SDK: minSdkVersion="9" targetSdkVersion="15"

I am testing my application on Nexus S with Jelly Bean.

Thanks in advance!

PS If somebody needs more specific details, please let me know.

EDIT

OK, All answers suggest that this is a normal behavior, but I still puzzled since I can find a lot applications that record voice call, using the microphone. Recording voice call is not my intention, but I thought I can use the microphone even during the voice call. Any suggestions?

EDIT

I just tested the application on Galaxy S Gingerbread and it worked! Now I am really puzzled and starting to understand what word "segmentation" means ...

回答1:

I would not call this normal, but you're entering platform-specific behavior here. Recording with AudioSource.MIC during a voice call will work on some devices, but not on others.

Just to name a few reasons that I've run into myself for why this functionality might've been disabled:

  • Some platforms only supports capturing microphone audio at a single sample rate at any given time. And since voice calls take priority over anything else (this is a phone after all) and voice calls require either 8 or 16 kHz sample rate, the decision about what to do when you have a ongoing recording when a voice call starts might be to simply mute the recording, so that your recording isn't filled with 8 kHz data when your app thinks it's getting 44.1 kHz for example.

  • If you leave a recorder idle (stopped but not released) during a voice call some platforms could stop transferring audio data from the microphone, effectively muting the voice call uplink. To avoid this, the vendor might've just decided that a recording during a voice call won't actually be routed to any input device, but rather just be filled with zeroes.

Disclaimer: I have not worked with the Nexus S, so I don't know what the reason was on that specific device.



回答2:

I believe this is normal behaviour, Audio data while CALL is connected will never be processed through Application processor on which Android is running. Usually the Audio chipset will switch it to stream coming from Modem.



回答3:

In theory, you can get a feed from the call itself (http://stackoverflow.com/questions/4194342/how-can-i-record-voice-and-record-call-in-android), but most makers apparently don't support this.