Coder Social home page Coder Social logo

crunker's Introduction

Crunker

Experimental, use in production with caution

Simple way to merge, concatenate, play, export and download audio files with the Web Audio API.

  • No dependencies
  • Tiny 1.8kB gzipped

Installation

yarn add crunker
npm install crunker

Example

let audio = new Crunker();

audio
  .fetchAudio("/song.mp3", "/another-song.mp3")
  .then(buffers => {
    // => [AudioBuffer, AudioBuffer]
    return audio.mergeAudio(buffers);
  })
  .then(merged => {
    // => AudioBuffer
    return audio.export(merged, "audio/mp3");
  })
  .then(output => {
    // => {blob, element, url}
    audio.download(output.blob);
    document.body.append(output.element);
    console.log(output.url);
  })
  .catch(error => {
    // => Error Message
  });

audio.notSupported(() => {
  // Handle no browser support
});

Condensed Example

let audio = new Crunker();

audio
  .fetchAudio("/voice.mp3", "/background.mp3")
  .then(buffers => audio.mergeAudio(buffers))
  .then(merged => audio.export(merged, "audio/mp3"))
  .then(output => audio.download(output.blob))
  .catch(error => {
    throw new Error(error);
  });

Merge

merge

Concat

concat

Methods

new Crunker({ sampleRate: 44100 })

Create a new Crunker. You may optionally provide an object with a sampleRate key, defaults to 44100.

crunker.fetchAudio(songURL, anotherSongURL)

Fetch one or more audio files.
Returns: an array of audio buffers in the order they were fetched.

crunker.mergeAudio(arrayOfBuffers);

Merge two or more audio buffers.
Returns: a single AudioBuffer object.

crunker.concatAudio(arrayOfBuffers);

Concatenate two or more audio buffers in the order specified.
Returns: a single AudioBuffer object.

crunker.padAudio(buffer, padStart, seconds);

Pad the audio with silence, at the beginning, the end, or any specified points through the audio.
Returns: a single AudioBuffer object.

crunker.export(buffer, type);

Export an audio buffers with MIME type option.
Type: 'audio/mp3', 'audio/wav', 'audio/ogg'.
Returns: an object containing the blob object, url, and an audio element object.

crunker.download(blob, filename);

Automatically download an exported audio blob with optional filename.
Returns: the <a></a> element used to simulate the automatic download.

crunker.download(blob, filename);

Automatically download an exported audio blob with optional filename.
Filename: String not containing the .mp3, .wav, or .ogg file extension.
Returns: the <a></a> element used to simulate the automatic download.

crunker.play(blob);

Starts playing the exported audio blob in the background.
Returns: the audio source object.

audio.notSupported(callback);

Execute custom code if Web Audio API is not supported by the users browser.
Returns: The callback function.

License

MIT

crunker's People

Contributors

jaggad avatar alynva avatar dependabot[bot] avatar fzxt avatar zackradisic avatar tothehit avatar homm 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.