Giter VIP home page Giter VIP logo

mp3recorder's Introduction

Mp3Recorder

Record web audio to an MP3 in mono or stereo.

Live demo.

Supports all modern browsers.

API

    import { Mp3Recorder } from './src/Mp3Recorder.mjs';

    let recorder = new Mp3Recorder();

    await recorder.configure(inputAudioNode, channels, bitRate);

    recorder.start();

    recorder.pause();

    recorder.resume();

    let bytes = await recorder.getRecordedSize();

    let mp3 = await recorder.stop();

Installation

Copy the files in src into your project.

  • Mp3RecorderWorklet.js: tiny AudioWorkletProcessor that feeds raw audio to the worker.
  • Mp3RecorderWorker.js: encodes audio in real time (using lamejs, inline in the file). We use a separate worker to avoid dropping frames during encoding (AudioWorkletProcessor has hard coded 128 byte buffer).
  • Mp3Recorder.mjs: coordinates worker threads and provides an API for them. This is what you use in your code. The other files are necessary evils because of the way web threading works.

API Details

Mp3Recorder()

You should only create one instance of Mp3Recorder to avoid proliferation of worker threads.

async configure(inputNode, channels, bitRate):

This can be called as many times as you want to change the audio node being recorded or to reconfigure the encoder.

  • inputNode: the AudioNode whose output we'll record
  • channels: 1 or 2 (mono or stereo)
  • bitRate: bit rate to encode at

start()

Start recording.

pause()

Pause recording.

resume()

Resume recording after it's been paused.

async getRecordedSize()

Return the number of bytes recorded so far.

async stop()

Stop recording and return the MP3 blob.

mp3recorder's People

Contributors

erictetz avatar

Stargazers

Daniel Liu avatar  avatar

Watchers

 avatar

mp3recorder's Issues

Make this a package

Any plans for making this an npm / yarn package, so we can easily install it?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.