23

I would like to live stream recorded audio from the browser to the server and play it. The server will end up being a embedded device that plays these audio streams.

So far I've successfully recorded audio and encoded it into a WAVE file and play it on the browser using the web audio API and following this tutorial.

Now I have a stream of .WAV encoded blobs. I tried finding ways to stream these to a nodejs backend with a web socket connection and play them using a npm module. But I haven't had any luck.

Does anyone know of any resources or modules I should follow? Maybe I should try a different approach? The audio needs to be played relatively quickly on the server since recording on the browser.

1

1 Answer 1

23

I'm doing this currently with some software that allows for streaming to internet radio servers via your web browser.

I use the WebAudio API along with getUserMedia to get live PCM audio data from the sound device. From there, I convert this data from 32-bit float to 16, 12, or 8 bit data depending on the amount of bandwidth available. This converted int samples are written to a stream setup with BinaryJS which wraps streams on both the Node.js and the client. As a bonus with BinaryJS, you can have as many streams open as you want, so I use a second stream over the same WebSocket connection for control data.

http://demo.audiopump.co:3000/

5
  • 1
    BinaryJS looks like a good option. Any idea of how to play the binary stream on speakers server side? Dec 31, 2013 at 16:53
  • @ConorPatrick That depends entirely on your platform. Each is different. There are NPM modules for most plaforms for audio playback.
    – Brad
    Dec 31, 2013 at 18:23
  • 1
    Would it be possible for you to post an example of the javascript you use to connect to the audio source and stream to the server? I've been trying to figure this out for months and don't feel like I'm any closer.
    – NealR
    May 5, 2014 at 1:59
  • 2
    @NealR A full example of streaming audio to node: github.com/noamtcohen/AudioStreamer
    – noamtcohen
    Sep 3, 2014 at 11:54
  • Thanks, @NealR, what would be your approach to saving chunks of the stream as sperate files? i.e. saving an audio file every 2 seconds for example out of the stream
    – Leo
    Nov 29, 2017 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.