I would like to accomplish something like this in the browser but plugin-free.
It's described in a fully functional Linux command line and in pseudocode:
$ arecord -d 5 -f dat -c 1 -f S16_LE -r 8000 |\
speexenc - - |\
curl -X PUT "https://api.example.com/record-sound" -T -
Pesudo-code:
-d 5
or stopped by the user, flush the request body and send
the request.Obviously this is a Linux command line but the algorithm have been successfully applied on:
I would like to achieve the same goal "efficient and fast streaming from microphone to a server" on the browser (old browsers are not my concern now). It doesn't have to be a REST server, WebSockets or whatever is possible are as good. Also Node.js based solution is prefered.
What I have tried so far:
getUserMedia
to upload the sound through recorder.js and XHR2
it works find except that:
xhr.send(data)
wav
format which is way bigger in size compared with ogg
and opus
I've asked a related question "How can I use Opus Codec from JavaScript" to seek other alternatives, and the answers there apply here to some extent:
Brad:
Unfortunately, it isn't currently possible to access browser codecs directly from JavaScript for encoding. The only way to do it would be to utilize WebRTC and set up recording on the server. I've tried this by compiling libjingle with some other code out of Chromium to get it to run on a Node.js server... it's almost impossible.
The only thing you can do currently is send raw PCM data to your server. This takes up quite a bit of bandwidth, but you can minimize that by converting the float32 samples down to 16 bit (or 8 bit if your speech recognition can handle it).
Hopefully the media recorder API will show up soon so we can use browser codecs.
OmarIthawi:
One way to do it is to compile Opus to Emscripten and hope that your PC can handle encoding using JavaScript. Another alternative is to use speex.js.