node-mumble
node-mumble copied to clipboard
Is there an example how to play/stream audio to Web Audio API ?
I am having very hard times to get this working.
I tried to convert the pcmdata do Float32Array but I always get audio with cracks. It is possible to hear and recognize voice but it's not clear and cracks a lot, unusable.
Can you please help me with this ?
Here is my code:
let audio = new Int16Array(pcmData.length / Int16Array.BYTES_PER_ELEMENT);
let length = audio.length;
for (let i = 0; i < length; ++i) {
audio[i] = pcmData.readInt16LE(i * Int16Array.BYTES_PER_ELEMENT);
}
let right = new Float32Array(audio.length);
let channelCounter = 0;
for (let i=0; i < audio.length; i++) {
let normalizedRight = audio[i] / 32768;
right[channelCounter] = normalizedRight;
channelCounter++;
}
let source = this.audioContext.createBufferSource();
let audioBuffer = this.audioContext.createBuffer(1, right.length, 48000);
audioBuffer.getChannelData(0).set(right);
source.buffer = audioBuffer;
source.connect(this.audioContext.destination);
if(this.startTime == 0) this.startTime = this.audioContext.currentTime + (audioBuffer.length / audioBuffer.sampleRate)/2;
source.start(this.startTime);
this.startTime += audioBuffer.length / audioBuffer.sampleRate;
You can take a look here: It's an old repository where I tried to implement a webclient for mumble: webmumble. It might give you an idea. Make sure to look at the "experiments" branch. Basically it transmits everything via websocket to the browser which in turn encodes and decodes the ogg in a webworker with a libopus that was compiled to javascript using emscripten.