Record audio and stream live


I need to record audio and stream live, I discovered that with HTML5 and JavaScript / jQuery it is possible and that it has plugins that can help me. I'm using one of them, the MediaStreamRecorder and I'm recording and streaming live to myself, but I can not broadcast to anyone, anyone knows How do I make this transmission? Probably using socket? Where is the file being recorded? How to send the file to the server in real time?

EDIT: How to send blob in real time to server?


Code used (the plugin is in github at this link: MediaStreamRecorder ):

<script src="//"> </script>

    Audio Recording using <a href=""
<div id="audios-container">

        var mediaConstraints = { audio: true };
        navigator.getUserMedia(mediaConstraints, onMediaSuccess, onMediaError);

        function onMediaSuccess(stream) {
            var audio = document.createElement('audio');
            audio = mergeProps(audio, {
                controls: true,
                src: URL.createObjectURL(stream)


            var mediaRecorder = new MediaStreamRecorder(stream);
            mediaRecorder.mimeType = 'audio/ogg';
            mediaRecorder.ondataavailable = function(blob) {
                var a = document.createElement('a');
       = '_blank';
                a.innerHTML = 'Open Recorded Audio No. ' + (index++);

                a.href = URL.createObjectURL(blob);


            // get blob after each 5 second!
            mediaRecorder.start(5 * 1000);

        function onMediaError(e) {
            console.error('media error', e);

        var audiosContainer = document.getElementById('audios-container');
        var index = 1;
asked by anonymous 01.06.2014 / 06:16

2 answers


After much research I get results using WebRTC-Experiment ( link ) and ( link ).

Server Code: ( link )

<script src=""></script><buttonid="audio">Audio stream</button>

var connection = new RTCMultiConnection('channel-654654-34434-12121');
connection.session = {
    data: true

document.querySelector('#audio').onclick = function() {

User Code: ( link )

<script src=""></script>

var connection = new RTCMultiConnection('channel-654654-34434-12121');
connection.session = {
    audio: true

07.06.2014 / 01:43

You have nowhere to run, when it comes to streaming the clients have to connect to you, or you are the server that distributes the data to everyone who is connected to you!

In reality, you open the audio in raw (raw audio) form on your data input device (microphone or other source) and send it to clients within fixed-size blocks, generally 2048, 4096 on the other side each client receives the values of this vector and gives the play encoding to some format (wav, mp3, etc)!

The javascript that you just presented takes the data of the microphone purely, I did not look fondly but these values must be in a short int vector or fixed size float32, just so you understand the process:

The captured microphone values can generally be in short or float32 they are a fixed-length vector, 2048 or 4096, etc. These values are passed to an encoder that encodes this vector to the desired format, of possession of the encoded vector the player touches this vector. This process runs in a loop and is fast enough not to promote latency

02.06.2014 / 21:59