AgoraIO-Community / AgoraWebSDK-NG

The Next Generation of Agora Web SDK
https://agoraio-community.github.io/AgoraWebSDK-NG/
161 stars 74 forks source link

Cannot publish audio track from file without remote users hearing audio track twice #119

Closed rohan-suri closed 3 years ago

rohan-suri commented 3 years ago

Describe the bug

I would like to publish an audio track from a file such that all users in a channel can hear the audio track including the user publishing the audio track. Here is my code for publishing and playing the audio track:

    const audioFileTrack = await AgoraRTC.createBufferSourceAudioTrack({
      source: myFile,
    });
    audioFileTrack.startProcessAudioBuffer();
    audioFileTrack.play();
    await agoraClient.publish(audioFileTrack);

The problem is that if the user is not wearing headphones, then the remote users both hear the published audio track twice, once from the published track and second from the user's local audio track feeding into their that person's microphone.

I could force the user to be muted when playing (but I would like people to talk) or I could remove the audioFileTrack.play() but then the publishing user does not hear the audio file. Any ideas on how to prevent the local audio track playing from feeding into the microphone?

HAHAHA44 commented 3 years ago

In browser, only the far-end audio received through the p2p connection will not be collected again when it is played.

If you want to play local audio and publish local microphone track, you have better to wear headphones.

rohan-suri commented 3 years ago

Thanks for the response! That's unfortunate regarding only that p2p connections are not collected again. Do you know if this is a browser setting or a configuration of the Agora sdk?

HAHAHA44 commented 3 years ago

This is a issue of Chrome. It seems Safari does not have this problem. https://github.com/webrtc/samples/issues/1243

rohan-suri commented 3 years ago

Thank you that link was helpful!