How do I convert the getUsermedia audio stream to a block or buffer?

I am receiving an audio stream from getUserMeda and then converting it to blob or buffer and sending it to the server as the sound goes. I am using socket.io to release it to the server, how can I convert the audio media stream to a buffer?

Below is the code I have written yet

navigator.getUserMedia({audio: true, video: false}, function(stream) {
webcamstream = stream;
var media = stream.getAudioTracks();
socket.emit("sendaudio", media);
},
function(e){
   console.log(e);
  }
});

      

How do I convert the stream to a buffer and pass it to the node.js server since the stream comes from the getusermedia function?

+3


source to share


1 answer


Per @MuazKhan's comment, use MediaRecorder (in Firefox, ultimately in Chrome) or RecordRTC / etc to capture the data in the blob. You can then export it using one of several methods to the server for distribution: WebSockets, WebRTC DataChannels, etc. Please note that they do NOT guarantee real-time data transfer, and MediaRecorder does not have bitrate control yet. If transmission is delayed, data may accumulate locally.



If realtime (re) transmission is important, it is highly recommended to use a server instead of PeerConnection (per @Robert's comment) and then convert it there to a stream. (How this is done will depend on the server, but you must have the Opus encoded data for repackaging or decoding and re-encoding.) While transcoding is usually not very good, in this case you would be best decoded via NetEq (webrtc jitter buffer .org and PacketLossConcealment code) and get a pure real-time audio stream for re-encoding for lossy and jitter streaming.

+6


source







All Articles