Miss any of our Open RFC calls?Watch the recordings here! »

audio-2.0.0

2.0.0 • Public • Published

Audio

experimental Build Status Greenkeeper badge Code Climate Downloads npm license

Class for high-level audio manipulations in javascript. An abstraction from the level of raw data and DSP to the level of natural sound manipulations.

Usage

npm install audio

const Audio = require('audio')

Use-cases

Load ./sample.mp3, trim, normalize, fade in, fade out, save:

Audio.load('./sample.mp3').then(audio =>
  audio
    .trim()
    .normalize()
    .fade(.5)
    .fade(-.5)
    .save('sample-edited.wav')
)

Record 4s of mic input.

navigator.getUserMedia({audio: true}, stream =>
 
    Audio.record(stream, (err, audio) => {
        audio.save('my-record.wav')
    })
)

Record and download 2 seconds of web-audio experiment

//create web-audio experiment
let ctx = new AudioContext()
let osc = ctx.createOscillator()
osc.type = 'sawtooth'
osc.frequency.value = 440
osc.start()
osc.connect(ctx.destination)
 
//record 2 seconds of web-audio experiment
let audio = Audio(osc, {duration: 2})
audio.on('end', () => {
    osc.stop()
    audio.download('experiment')
})

Download AudioBuffer returned from offline context

//setup offline context
let offlineCtx = new OfflineAudioContext(2, 44100*40, 44100)
audioNode.connect(offlineCtx)
 
//process result of offline context
offlineCtx.startRendering().then((audioBuffer) => {
    Audio(audioBuffer).save()
})

Montage audio

let audio = Audio.load('./record.mp3', (err, audio) => {
    //repeat slowed down fragment
    audio.write(audio.copy(2.1, 1).scale(.9), 3.1)
 
    //delete fragment, fade out
    audio.delete(2.4, 2.6).fadeOut(.3, 2.1)
 
    //insert other fragment not overwriting the existing data
    Audio('./other-record.mp3', (err, otherAudio) => {
        audio.insert(2.4, otherAudio)
    })
 
    audio.download('edited-record')
})

Render waveform of HTML5 <audio>

const Waveform = require('gl-waveform')
 
//create waveform renderer
let wf = Waveform();
 
//get audio element
let audioEl = document.querySelector('.my-audio')
audioEl.src = './chopin.mp3'
 
//create audio holder
let audio = new Audio(audioEl)
audio.on('load', (err, audio) => {
    let buf = audio.readRaw(4096)
    let data = buf.getChannelData(0)
 
    //put left channel data to waveform renderer
    wf.push(data);
})

Process audio with audio-* modules

const Biquad = require('audio-biquad')
 
let lpf = new Biquad({frequency: 2000, type: 'lowpass'})
let audio = Audio(10).noise().process(lpf)
Data handle - subaudio, for sprites etc

Load intro, append 1s pause, start recording. Once ended, save as file.

Audio(['./intro.mp3', 1, MediaStream]).once('ready', (err, audio) => audio.save(Date() + '-recording.mp3'))

API

1. Core

2. Manipulations

3. Metrics

4. Playback

See Also

  • audiojs − open-source audio components for javascript
  • web-audio-api − web-audio-api implementation for nodejs

Related

Credits

Acknowledgement to contributors:

License

MIT © audiojs.

Install

npm i audio-2.0.0

DownloadsWeekly Downloads

2

Version

2.0.0

License

MIT

Unpacked Size

96.2 kB

Total Files

20

Last publish

Collaborators

  • avatar