Note that there are some explanatory texts on larger screens.

plurals
  1. POSend audio to Nodejs in a bufferred and efficient way - perhaps with WebRTC
    text
    copied!<p>I would like to accomplish something like this in the browser but plugin-free.</p> <p>It's described in a fully functional Linux command line and in pseudocode:</p> <pre><code>$ arecord -d 5 -f dat -c 1 -f S16_LE -r 8000 |\ speexenc - - |\ curl -X PUT "https://api.example.com/record-sound" -T - </code></pre> <p>Pesudo-code: </p> <ol> <li>Open the mic,</li> <li>Open the connection to the API endpoint</li> <li>Read bytes from the mic on the rate of 8000 Hz (wave pcm signed 16-bit little endian mono 8000 Hz)</li> <li>Encode the bytes to Speex in chunks (<a href="http://speex.org" rel="nofollow">http://speex.org</a>)</li> <li>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</li> <li>When mic stops giving results (either by a timer <code>-d 5</code> or stopped by the user, flush the request body and <code>send</code> the request.</li> <li>Wait for JSON (or anything else) results in response body</li> </ol> <p>Obviously this is a Linux command line but the algorithm have been successfully applied on: </p> <ol> <li>Linux - using the command above</li> <li>iOS - iPhone and iPad</li> <li>Java2SE on Windows</li> </ol> <p>I would like to achieve the same goal <strong>"efficient and fast streaming from microphone to a server"</strong> 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 <strong>Node.js</strong> based solution is prefered.</p> <p>What I have tried so far:</p> <ul> <li>Successfully used a <a href="http://code.google.com/p/flash-videoio/" rel="nofollow">VideoIO.swf</a> which is a Flash based solution and <a href="http://code.google.com/p/rtmplite/" rel="nofollow">RTMPLite</a> on the server to receive video. It's actually a very good solution in terms of functionality except that: <ul> <li>It requires user approval through very bad UI</li> <li>It's not a standard way of doing web and don't allow good error detection and such</li> </ul></li> <li>Successfully used <code>getUserMedia</code> to upload the sound through <a href="https://github.com/mattdiamond/Recorderjs" rel="nofollow">recorder.js</a> and <code>XHR2</code> it works find except that: <ul> <li>It is actually slow because XHR2 needs full data before request can be made using <code>xhr.send(data)</code></li> <li>It is even slower since I could only upload <code>wav</code> format which is way bigger in size compared with <code>ogg</code> and <code>opus</code></li> </ul></li> <li>Researched on the use of WebRTC but couldn't find any resource that mentioned anything other than peer-to-peer connections</li> </ul>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload