HTML5 & Web audio api: streaming microphone data from browser to server. Perfect transport and data compression

I want to take audio input from a browser and pass it to multiple listeners. The intended use is for music, so the quality should conform to the mp3 standard or so.

I tried to make two paths, both giving unsuccessful results:

WebRTC

  • Audio streaming between browsers works fine, but the sound quality doesn't seem to be customizable, although what I saw. (I saw that it uses the Opus sound codec, but does not seem to provide any controls).
  • Does anyone know how to improve sound quality in WebRTC streams?

Web sites

  • The problem is transportation from the browser to the server. The PCM audio data that I can get using the method below turned out to be too large to transmit to the server many times over web ports. Stream works fine in high-speed Internet environments, but on slower Wi-Fi it is unsuitable.

    var context = new webkitAudioContext() navigator.webkitGetUserMedia({audio:true}, gotStream) function gotStream (stream) { var source = context.createMediaStreamSource(stream) var proc = context.createScriptProcessor(2048, 2, 2) source.connect(proc) proc.connect(context.destination) proc.onaudioprocess = function(event) { var audio_data = event.inputBuffer.getChannelData(0)|| new Float32Array(2048) console.log(audio_data) // send audio_data to server } } 

So, the main question is, is there a way to compress PCM data in order to simplify the flow to the server? Or maybe there is an easier way to do this?

+8
html5 websocket webrtc getusermedia web-audio
source share
2 answers

There are many ways to compress PCM data, of course, but really, your best bet is to get WebRTC to work correctly. WebRTC is designed for this - adaptive streaming media - although you do not define what you mean by β€œmultiple” listeners (there is a huge difference between 3 listeners and 300,000 simultaneous listeners).

+3
source share

There are several possible ways to oversampling and / or compressing your data, but none of them are native. I overfulfilled the data to 8Khz Mono (your mileage may vary) using xaudio.js lib from speex.js . You can also compress the stream using speex, although this is usually only used for audio. In your case, I would probably send the stream to the server, compress it and transmit it to the audience. I really do not think that a simple browser is good enough to serve the data of a huge audience.

+2
source share

All Articles