0

Having a spring-boot project which has to stream audio coming from a SIP client connected to asterisk with codec G711 ALAW.

I am able to get and send the pcm data through a UDP connection between the sip client and spring-boot project.

The goal is to send this packets through a web socket to the client and play those audio bytes in the browser.

In the browser I hear the audio with a lot of noise using this player to play pcm packets I receive from the web socket with this parameters:

<script>
 var player = new PCMPlayer({
   encoding: '16bitFloat',
   channels: 1,
   sampleRate: 8000,
   flushingTime: 1000
});

function StartSession() {
  ws = new WebSocket(socketURL);
  ws.binaryType = 'arraybuffer';
  ws.addEventListener('message', function (event) {
    player.feed(new Int16Array(event.data));
  });
}

function CloseSession() {
  if (ws != null) {
    ws.close();
  }
}
</script>
miken32
  • 42,008
  • 16
  • 111
  • 154
Flamur Dervishi
  • 181
  • 1
  • 6
  • 18
  • This is more an audio question than a spring-boot question. Looks like you're using 16bit with sampling rate of 8000. That's a very low quality audio. Also I don't see how your spring boot is picking up the packages and forwarding it to the browser, but it can be that it loses audio quality there if it doesn't handle the packages correctly. Edit: Added as comment instead of answer - on suggestion of @miken32 – BarbetNL Dec 23 '21 at 13:45
  • When I use a c# `ClientWebSocket` and `NAudio` and store the received bytes into a wav file, we can play the file correclty. So now we are sure that the problem is on the player side. – Flamur Dervishi Dec 30 '21 at 10:42
  • How it related to asterisk at all? – arheops Dec 31 '21 at 02:16
  • We are getting the stream from an asterisk with G.711 alaw format – Flamur Dervishi Dec 31 '21 at 11:55

0 Answers0