Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Web Audio API - record to MP3?

Tags:

I am asking because I couldn't find the answer anywhere. I have successfully implemented RecorderJS in order to record microphone input in JS. However, the recorded file is WAV which results in large files. I am looking for a way to record with JS directly to MP3, or encode the bits somehow to MP3 instead of WAV.

How can it be done? Is there a Web Audio API function that can do that or JS MP3 encoder of some sort?

like image 595
Light Avatar asked Jun 02 '13 10:06

Light


People also ask

Is there a way to record audio from a website?

One of the best ways to record audio on a website is to use a Chrome Extension like Audio Capture. This tool can be easily installed on the browser, ready to use whenever you need to record audio on any tab. It also allows you to mute all other tabs to avoid accidently recording them as well.

Can I use MediaStream recording API?

At the moment the MediaStream Recorder API is only supported by Chrome, Firefox, Opera and Edge 79 (Chromium). Please comment on this Safari/WebKit feature request to request Safari support.

Can I record audio from Chrome?

Chrome Audio Capture is a Chrome extension that allows users to record any audio playing on the current tab. Multiple tabs can be recorded simultaneously. Recordings can be saved as either .


2 Answers

The only Javascript MP3 encoder I've seen is https://github.com/akrennmair/libmp3lame-js, which is a port using emscripten. It's supposed to be slow, and I've never used it.

I don't know of any natively-written Javascript MP3 encoders, and encoding is not covered by the Web Audio API.

like image 114
cwilso Avatar answered Oct 05 '22 23:10

cwilso


There's a library written in pure javascript, called lamejs. To encode mp3s from raw audio. It is much faster than emscripten compile of libmp3lame. https://github.com/zhuker/lamejs

Example usage:

lib = new lamejs();
mp3encoder = new lib.Mp3Encoder(1, 44100, 128); //mono 44.1khz encode to 128kbps
samples = new Int16Array(44100); //one second of silence
var mp3 = mp3encoder.encodeBuffer(samples); //encode mp3
like image 28
Alex Zhukov Avatar answered Oct 06 '22 01:10

Alex Zhukov