I want to play twilio media stream in browser in real time. For this I am using websocket to send twilio stream from node.js server to browser. I am converting the twilio media stream by using wavefile npm with the following code :-
// Server Side Code
const wav = new WaveFile();
wav.fromScratch(1, 8000, '8m', Buffer.from(item.audioPayload, "base64"));
wav.fromMuLaw();
wav.toSampleRate(44100);
let dataURI = wav.toDataURI();
item.audioPayload = dataURI;
this.sendAgentMessage(item, this.connection);
And at the browser side I am playing audio using this :-
// Client side code
var snd = new Audio(message.audioPayload);
snd.play();
Now while playing the audio I am getting very much noise and distortion.
Please help me with this.