Git Product home page Git Product logo

audiobuffer-to-wav's Introduction

audiobuffer-to-wav

stable

Encodes the contents of an AudioBuffer from the WebAudio API as WAVE. Supports 16-bit PCM and 32-bit float data.

The code for this has been adapted from the export feature of Recorder.js.

PRs welcome.

Install

npm install audiobuffer-to-wav --save

Example

var toWav = require('audiobuffer-to-wav')
var xhr = require('xhr')
var context = new AudioContext()

// request the MP3 as binary
xhr({
  uri: 'audio/track.mp3',
  responseType: 'arraybuffer'
}, function (err, body, resp) {
  if (err) throw err
  // decode the MP3 into an AudioBuffer
  audioContext.decodeAudioData(resp, function (buffer) {
    // encode AudioBuffer to WAV
    var wav = toWav(buffer)
    
    // do something with the WAV ArrayBuffer ...
  })
})

See the demo for an example of loading MP3, decoding it, and triggering a download of the encoded WAV file.

A more advanced example might be to write the file using Node and Electron or hihat, i.e. an easy way to convert MP3/OGG/etc to WAV.

Usage

NPM

arrayBuffer = encodeWAV(audioBuffer, [opt])

Encodes the AudioBuffer instance as WAV, returning a new array buffer. Interleaves multi-channel data, if necessary.

By default, exports with 16-bit PCM (format: 1). You can specify opt.float32 instead, which will write format 3 with 32-bit float data.

License

MIT, see LICENSE.md for details.

audiobuffer-to-wav's People

Contributors

mattdesl avatar

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.