0
votes

How to give live stream audio data in to html5 audio tag.

I am receiving continuous chunks of audio data [ wav formatted ] through web sockets from the nodejs server. How to make this data feed into audio tag in case of live streaming.

In my simple html file i have audio tag like below:

<audio id="audiowav" type="audio/wav" controls autoplay></audio> 

Below is the set of codes used in my javascript file:

var socket = new WebSocket('ws://localhost:port');

socket.onmessage = function (event) {

//  Data is coming at regular intervals

var stream = event.data;  //type is audio/wav ( byte codes from nodejs server )

// how to feed this data to audio tag
}

Please provide some hints to proceed.

1
Any update on this issue? - Shalak Shetty

1 Answers

0
votes

Until we get browsers supporting WAV via MSE, you'll have to use the WebAudio API and a ScriptProcessorNode, and manually buffer and play back your data.