Multitrack audio editor: the JavaScript library
Engine of a multitrack audio editor: decoding, cutting and joining audio without clicks, fades and volume, live playback, mixdown and export to WAV or MP3, projects in the browser storage.
@openlibsdev/audio-editor- v1.0.0
- ES module
- MIT
Installation
With a bundler or Node-style imports:
npm install @openlibsdev/audio-editorimport AudioEditor from "@openlibsdev/audio-editor";Or straight in a page, without a build step (jsDelivr resolves the dependencies):
<script type="module">
import AudioEditor from "https://cdn.jsdelivr.net/npm/@openlibsdev/audio-editor@1.0.0/+esm";
</script>Usage
import AudioEditor from "@openlibsdev/audio-editor";
const file = document.querySelector("input[type=file]").files[0];
const buffer = await AudioEditor.decodeAudio(await file.arrayBuffer());
const part = AudioEditor.sliceAudioBuffer(buffer, 0, Math.min(2, buffer.duration));
const wav = AudioEditor.audioBufferToWav(part); // a Blob
const mp3 = await AudioEditor.encodeToFormat(part, "mp3", 192);API
AudioEditor.decodeAudio(arrayBuffer)
Decodes an audio file (ArrayBuffer) into an AudioBuffer.
AudioEditor.sliceAudioBuffer(buffer, startSec, endSec)
Cuts out a piece from start to end (seconds) as a new AudioBuffer; the edges get a short fade against clicks.
AudioEditor.spliceOutRange(buffer, startSec, endSec)
Removes a piece and joins the rest.
AudioEditor.computePeak(buffer)
Highest sample level, 0–1.
AudioEditor.audioBufferToWav(buffer)
Encodes an AudioBuffer to a WAV Blob.
AudioEditor.audioBufferToMp3(buffer, kbps)
Encodes an AudioBuffer to an MP3 Blob at the given bitrate.
AudioEditor.encodeToFormat(audioBuffer, format, bitrate)
Encodes to "wav" or "mp3".
AudioEditor.renderMixdown(tracks, opts)
Mixes tracks into one AudioBuffer, with their position, pan, volume, fades, mute and solo.
AudioEditor.renderSingleTrack(track, opts)
Renders one track with its volume and fades.
AudioEditor.startAudio()
Starts the audio context; call it from a user action (a click).
AudioEditor.startLive(track, opts)
Plays a track live.
AudioEditor.stopLive(live)
Stops live playback.
AudioEditor.saveProjectToDb(project)
Saves a project to the browser storage (IndexedDB).
AudioEditor.loadProjectFromDb(id)
Loads a saved project by its id.
AudioEditor.now()
Current time of the audio clock in seconds (the time base for startLive and scheduleTrackFades).
AudioEditor.scheduleTrackFades(gainParam, track, startAtCtxTime, segmentStartOffsetInTrack, segmentDuration, audible, masterVolume)
Schedules a track's volume on a gain parameter: fade in, fade out, track volume and master volume, or silence when the track is muted.
AudioEditor.APP
Name and version of the library: {name, version}.
Dependencies
What the library loads, with the licenses (all are listed on the Licenses page).
| Name | Version | License | Files |
|---|---|---|---|
| @breezystack/lamejs | 1.2.7 | LGPL-3.0 | License · Source code |
| tone | 15 | MIT | License · Source code |
| wavesurfer.js | 7 | BSD-3-Clause | License · Source code |
| wavesurfer.js | 7 | BSD-3-Clause | License · Source code |
| wavesurfer.js | 7 | BSD-3-Clause | License · Source code |