0

I've been developing an audio conference application with Web Audio API and Node.js. One person will speak and other clients who are connected should hear him.

On the client-side I'm encoding PCM samples with libopus before sending them into server.

On the server-side I'm just sending those encoded packets back to users who are connected, and finally on each client I'm decoding those packets back to samples that can be played with Web Audio API.

When I'm testing the application on local environment everything is working just fine. On production environment, when the clients can connect from outside local space, couple major problems will occur.

  1. Some clients will have a delay in their audio which seems to be increasing. For example, if the stream has been going on for 1min the delay for some clients can be as big as 10 seconds, and after couple of minutes the delay for some clients is even bigger 30-50 seconds.

  2. Some clients have no problems.

  3. Especially the clients that are experiencing the delay, the sound is extremely low-pitched. This can happen for the clients who have no delay in their audio aswell.

dvalinn
  • 85
  • 8

1 Answers1

1

Thats because you can have different sample rates with different sound cards. So in this case the audio is heigh-pitched and lag (From PC1->PC2), and low-pitched and delayed with time going on (From PC2->PC1). In this case PC1's sample rate is lower than PC2.

you have to write a resampler to solve this. Check the sample rates on different PCs:

var audioCtx = new AudioContext();
var mySampleRate = audioCtx.sampleRate;

Check my post about none WebRTC solution: Can I stream microphone audio from client to client using nodejs?

can you give me the link to the Opus Lib you used ? Maybe I'll itegrate this in my project as well.

Community
  • 1
  • 1
Cracker0dks
  • 2,422
  • 1
  • 24
  • 39
  • https://github.com/Mido22/recordOpus/tree/8f0c312a3f45834d57c43f0758d773ccdd03d2e3/client/scripts libopus + opus.js. – dvalinn Jul 21 '15 at 12:10
  • Just for clarification, that's not my project, I just took those libraries from there. – dvalinn Jul 22 '15 at 05:49
  • I tried to change the samplerate from OS but AudioContext always returns 44100. Is this normal? – dvalinn Jul 22 '15 at 10:12
  • I never tried this because you cant expect that every user change this settings. So I dont know if this works. Have you restart your browser and maybe the OS too ? – Cracker0dks Jul 22 '15 at 11:47
  • Yeah, I did restart the browser. I've now tried to check what audioCtx.sampleRate returns on different computers and every single one so far returns 44100. – dvalinn Jul 22 '15 at 15:21
  • with same sample rate you should not have any pitch. Maybe the browser has direkt access to the sound card without windows settings. Dont know why u get low pitch without any code then. – Cracker0dks Jul 22 '15 at 17:31
  • Btw, have you tried your application without web workers? if you have, what happened? – dvalinn Aug 04 '15 at 12:14
  • i haven't, but if you get many users connected and want to handle all of them in your main js thread it will not work (just a dependes on the amount of users). You site page will not react in time and you will get lags in your own recording i guess. – Cracker0dks Aug 08 '15 at 12:35
  • One more thing. At which point you are mixing user's audio? My application currently works fine if there is two users ( two separate inputs and outputs ) but if third one joins, the audio starts stuttering. – dvalinn Sep 18 '15 at 10:07
  • in this file: https://github.com/cracker0dks/nodeJsVoip/blob/master/webcontent/js/voip.js line 191. I add all the voice data into the output array. This is in the main.js and combine all upsampled voice data at this point. – Cracker0dks Sep 19 '15 at 12:34