Get amplitude of audio with its source/object/streamType

Viewed 1275

Can any one please help me to find any way to find amplitude of different audioPlayer with in app? I need to know the amplitude of videoCall's audio in my app.

Example in my app I have a videoPlayer (youtube) and videoCall feature. So when I get videoCall, I need to slow/stop the videoPlayer's sound when someOne speaks on videoCall. Is there any way to find that?

I found a method to get amplitude of phone's audioPlayer, but this provides amplitude of all kind of audios playing in app without sending any identifier of source or streamType(MUSIC_STREAM or CALL_STREAM) or any thing different using which I can identify source of given amplitude like its of player or videoCalls.

This will only help if I will provide audioSessionId of AudioPlayer in Visualizer(audioSessionId), but I can't get audioSessionId of any player (videoCall, youtube), because of ThirdPartySDK.

private void createVisualizer(){
    int rate = Visualizer.getMaxCaptureRate();
    Visualizer audioOutput = new Visualizer(0); //  get output audio stream
    audioOutput.setDataCaptureListener(new Visualizer.OnDataCaptureListener() {
        @Override
        public void onWaveFormDataCapture(Visualizer visualizer, byte[] waveform, int samplingRate) {
            float intensity = ((float) waveform[0] + 128f) / 256;
            Log.d("visualizer = ", "visualizer = "+visualizer+ "visualizer = "+String.valueOf(intensity));
        }

        @Override
        public void onFftDataCapture(Visualizer visualizer, byte[] fft, int samplingRate) {

        }
    },rate , true, false); // waveform not freq data
    Log.d("rate", String.valueOf(Visualizer.getMaxCaptureRate()));
    audioOutput.setEnabled(true);
}

Any suggestion would be helpful, Thanks in advance.

1 Answers

I found solution, the SDK I used for VideoCall provides all user's voice level, So I used that to implement my feature.

And other solution I found was to use MediaRecorder, which provides sound's level of different sources like - MIC, VOICE_CALL etc. But as SDK was already using MediaRecorder internally and android doesn't allow to use 2 instances of MediaRecorder at a same time So it didn't work for me.

android: Detect sound level

Related