3

I am currently working on an app which is running in the background and muting the microphone during incoming and outgoing calls.But am unable to mute the microphone when there is any type audio recording. It will be of great help if I am provided with any type of solutions.

Thanks in advance

4 Answers4

0

I assume your talking about a Android app, but you should be more concise in your questions. Regardless, this is a post about muting the microphone which should answer your question. How does setMicrophoneMute() work?

Community
  • 1
  • 1
0

AudioManager::setMicrophoneMute only applies to voice calls (and VoIP). It's possible that it will affect recordings as well on some products, but there's no guarantee that it will, so you can't rely on it.

It should still mute the voice call uplink so that the other party can't hear what you're saying even if there's a recording ongoing. If it doesn't I would consider that a bug in the implementation of the device you're testing this on. However, what you say will end up in the recording that you do locally (unless you're using the VOICE_DOWNLINK AudioSource).

Michael
  • 57,169
  • 9
  • 80
  • 125
0

If you don't want to record audio while video recording. You can set

AudioManager.setStreamMute(AudioManager.STREAM_MUSIC, true);

It also work by AudioManager.STREAM_SYSTEM for some devices.

user3168958
  • 111
  • 3
0

There is no direct method to mute on AudioRecorder. We need to add some trick for mute the recording.

What I can do is, I download silence wav file and convert it to byte and add on the byte array. When user click on Mute Button, isMuteClick = true and when unmute it will be false.

while (isStreaming) 
                {
                    if(!isMuteClick){
                        // read() is a blocking call // can set blocking see docs
                        int bytesRead = recorder.read(readBuffer, 0,bytesReadTotal); 
                    
                        bytesReadTotal += bytesRead; // above ...chunk - bytesReadTotal);
                        mainBuffer.write(readBuffer, 0, bytesRead);
                       
                    }else{
                        int bytesRead = recorder.read(WavToByteArray(R.raw.silence), 0, chunk - bytesReadTotal); // 505  // 4410 //chunk - bytesReadTotal
                       
                        bytesReadTotal += bytesRead; // above ...chunk - bytesReadTotal);
                        mainBuffer.write(WavToByteArray(R.raw.silence), 0, bytesRead);
                    }
                } /

And here is code for converting silence wav file to byte array

private byte[] WavToByteArray(int resourceId) {
    byte[] filteredByteArray = new byte[1024];
    try {
        InputStream inputStream = this.getResources().openRawResource(resourceId);
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        byte[] soundBytes = new byte[1024];

        int i = Integer.MAX_VALUE;
        while ((i = inputStream.read(soundBytes, 0, soundBytes.length)) > 0) {
            outputStream.write(soundBytes, 0, i);
        }

        inputStream.close();
        outputStream.close();

        // remove  .wav header
        byte[] audioBytes = outputStream.toByteArray();
        filteredByteArray = Arrays.copyOfRange(audioBytes, 44, audioBytes.length);
    } catch (Exception e) {
        e.printStackTrace();
    }

    return filteredByteArray;
}
shubomb
  • 672
  • 7
  • 20