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:
- Open the mic,
- Open the connection to the API endpoint
- Read bytes from the mic on the rate of 8000 Hz (wave pcm signed 16-bit little endian mono 8000 Hz)
- Encode the bytes to Speex in chunks (http://speex.org)
- Write the byte chucks you get from Speex encoder to the webservice request body in chunks - this a lot of bandwidth is saved and bytes are sent as soon as they're available
- When mic stops giving results (either by a timer
-d 5
or stopped by the user, flush the request body andsend
the request. - Wait for JSON (or anything else) results in response body
Obviously this is a Linux command line but the algorithm have been successfully applied on:
- Linux - using the command above
- iOS - iPhone and iPad
- Java2SE on Windows
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:
- Successfully used a VideoIO.swf which is a Flash based solution and RTMPLite on the server to receive video. It's actually a very good solution in terms of functionality except that:
- It requires user approval through very bad UI
- It's not a standard way of doing web and don't allow good error detection and such
- Successfully used
getUserMedia
to upload the sound through recorder.js andXHR2
it works find except that:- It is actually slow because XHR2 needs full data before request can be made using
xhr.send(data)
- It is even slower since I could only upload
wav
format which is way bigger in size compared withogg
andopus
- It is actually slow because XHR2 needs full data before request can be made using
- Researched on the use of WebRTC but couldn't find any resource that mentioned anything other than peer-to-peer connections