9
I need to record audio and broadcast live, I found that with HTML5 and Javascript/jQuery is possible and that has plugins that can help me. I’m wearing one of them, the Mediastreamrecorder and I’m recording and broadcasting to myself live, only I can’t transmit to everyone, does anyone know how I do this transmission ? Probably using socket ? Where is the file being saved ? How to send the file in real time to the server ?
EDIT: How to send the blob in real time to the server ?
LINK IN JSFIDDLE: http://jsfiddle.net/C8WHd/2/
Code used (the plugin is on github at this link: Mediastreamrecorder):
<script src="//www.webrtc-experiment.com/MediaStreamRecorder.js"> </script>
<h1>
Audio Recording using <a href="https://github.com/streamproc/MediaStreamRecorder"
target="_blank">MediaStreamRecorder</a>
</h1>
<div id="audios-container">
</div>
<script>
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)
});
audio.play();
audiosContainer.appendChild(audio);
audiosContainer.appendChild(document.createElement('hr'));
var mediaRecorder = new MediaStreamRecorder(stream);
mediaRecorder.mimeType = 'audio/ogg';
mediaRecorder.ondataavailable = function(blob) {
var a = document.createElement('a');
a.target = '_blank';
a.innerHTML = 'Open Recorded Audio No. ' + (index++);
a.href = URL.createObjectURL(blob);
audiosContainer.appendChild(a);
audiosContainer.appendChild(document.createElement('hr'));
};
// 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;
</script
What’s the problem? Could you publish your code so we can analyze?
– Felipe Avelar
added code!
– Alan PS
There is no file being recorded. It simply stores the audio bytes (and possibly transmits them) as it receives them. The point is, where’s your "everyone"? It is quite possible that you need a server to forward the audio bytes to the other clients, since only via Javascript client-side, it is not possible to create a socket where other external clients can connect. At the beginning of the project description there are links with examples to transmit: https://github.com/muaz-khan/WebRTC-Experiment/tree/master/RecordRTC#how-recordrtc-encodes-wavwebm
– carlosrafaelgn
@carlosrafaelgn I use PHP, but I’ve never used sockets in php, I’ll search on, but I still don’t know how to send the file in real time to the server, if anyone has any answers...
– Alan PS
So, @user3230262. There is no file to transmit... Just an array of bytes that should be transmitted as quickly as possible to the server. Take a look at the source code of this page here, which is an example of me drawing audio on the screen. These other two questions also address the general idea of this capture... http://answall.com/questions/11640/como-capturr-audio-do-micropone-usando-api-de-audio-do-html5 and http://answall.com/questions/14484/capturing-audio-pelo-microfone-via-js-ou-html
– carlosrafaelgn
@carlosrafaelgn have any idea how I transmit this data ? examples!!!
– Alan PS
The Ajax example of the answer to this question is a good start ;) http://answall.com/questions/14484/capturing-audio-pelo-microfone-via-js-ou-html
– carlosrafaelgn