Search code examples
javascriptnode.jsaudiostreamingaudio-streaming

Streaming audio from the browser to a node.js server with a specific MIME type


What I need: Streaming live audio from the browser to a node.js server in WAV format.

Sounds fairly simple - The Problem: Using getUserMedia you get the audio-stream BUT in audio/webm format. The node.js server is connected to a speech-to-text engine(deepspeech) which CAN ONLY process the stream in WAV format.

What already works: I can already record a fixed length WAV audio blob (via RecorderJs) and send that finished recording to the node.js server and get its stream from readFileSync server side. Repository here (master working only). But I don't have a fixed recording anymore and want to live-stream that audio continuously.

As of now I am unsure if that is within the possibilities of node.js or any existing library. I've looked into ffmpeg, but didn't find a way to change the encoding of a stream with that. I was only able to change the encoding of a fixed file/blob with ffmpeg.

I'd appreciate it if someone could lead me into the right direction so I know where to start.


Solution

  • FFmpeg is the way to go.

    I've looked into ffmpeg, but didn't find a way to change the encoding of a stream with that.

    Use - for the input file, and - for the output file. Then use STDIN/STDOUT streams on your Node.js child process.