Tuesday, 2 February 2021

Echo Cancellation in Chrome not working as expected (and possible echo alternatives)?

I am currently trying to record the user's microphone using MediaRecorder and streaming the chunks to my server. However if the user isn't using headphones and someone else is talking through the speakers, the microphone is picking the other person's speech up. This is a problem as I combine the audio streams later. I assumed the echoCancellation feature would solve this.

Code:

 let streamStarted = false;

    const stream = await navigator.mediaDevices.getUserMedia({
      audio: { echoCancellation: true, noiseSuppression: true },
      video: true
    });
    const options = { mimeType: 'video/webm' };

    mediaRecorder = new MediaRecorder(stream, options);

    socket.emit('START_STREAM', JSON.stringify({ meetingId: meeting.id, email, time: Date.now() }));

    mediaRecorder.ondataavailable = async (event) => {
      if (!streamStarted) {
        setMeetingChanging(false);
        setRecording(true);
        streamStarted = true;
      }

      if (event.data.size > 0) {
        socket.emit('STREAM_CHUNK', { email, blob: await event.data, meetingId: meeting.id });
      } else {
        return;
      }
    };

    mediaRecorder.start(1000);

As it currently stands, I get echo in the final results, as I get the original user's input + the same speech through the other user's input.

Any ideas or suggestions? I've also looked at echo supression server-side but haven't found anything that can do it.

Thanks!



from Echo Cancellation in Chrome not working as expected (and possible echo alternatives)?

No comments:

Post a Comment