peasy-audio
v0.2.2
Published
Audio processing library for Node.js — convert, trim, merge, normalize, fade, speed. FFmpeg-powered, TypeScript-first.
Maintainers
Readme
peasy-audio
Audio processing library for Node.js -- convert between 6 formats (MP3, WAV, OGG, FLAC, AAC, M4A), trim segments, merge files, normalize volume, apply fade effects, adjust speed, and generate silence. FFmpeg-powered, TypeScript-first with full type safety.
Built from PeasyAudio, a free online audio toolkit with 10 browser-based tools for converting, trimming, merging, normalizing, and analyzing audio files.
Try the interactive tools at peasyaudio.com -- audio conversion, trimming, merging, normalization, and analysis
Table of Contents
- Prerequisites
- Install
- Quick Start
- What You Can Do
- TypeScript Types
- API Reference
- REST API Client
- Learn More
- Also Available
- Peasy Developer Tools
- License
Prerequisites
peasy-audio uses FFmpeg under the hood. Install it before using this library:
| Platform | Command |
|----------|---------|
| macOS | brew install ffmpeg |
| Ubuntu/Debian | sudo apt install ffmpeg |
| Fedora/RHEL | sudo dnf install ffmpeg-free |
| Windows | choco install ffmpeg |
Install
npm install peasy-audioQuick Start
import { info, convert, trim, merge, normalize } from "peasy-audio";
// Get audio file metadata
const metadata = await info("song.mp3");
console.log(metadata.duration, metadata.sampleRate); // 240.5 44100
// Convert MP3 to WAV
const wavPath = await convert("song.mp3", { format: "wav" });
// Trim to 30-second clip
const clip = await trim("song.mp3", { start: 10, duration: 30 });
// Merge multiple audio files
const combined = await merge(["intro.mp3", "main.mp3", "outro.mp3"]);
// Normalize volume to consistent levels
const normalized = await normalize("quiet-recording.mp3");What You Can Do
Audio Info & Metadata
Every audio file has metadata -- duration, sample rate, channels, bitrate, and codec information. The info() function uses FFprobe to extract this data without decoding the entire file, making it fast even for large files.
import { info } from "peasy-audio";
// Extract audio metadata using FFprobe
const meta = await info("podcast.mp3");
console.log(meta.duration); // 3600.5 (seconds)
console.log(meta.sampleRate); // 44100 (Hz)
console.log(meta.channels); // 2 (stereo)
console.log(meta.bitrate); // 320000 (bits/sec)
console.log(meta.format); // "mp3"Learn more: Audio Format Guide: MP3, AAC, FLAC, WAV, OGG · What is Bitrate? · What is Sample Rate?
Format Conversion
Audio format conversion transforms audio data between container formats and codecs. Common conversions include MP3 to WAV (for editing), WAV to FLAC (lossless archiving), and any format to AAC/M4A (Apple ecosystem compatibility).
| Format | Extension | Use Case |
|--------|-----------|----------|
| MP3 | .mp3 | Universal playback, streaming |
| WAV | .wav | Editing, uncompressed quality |
| OGG | .ogg | Open-source, web audio |
| FLAC | .flac | Lossless archiving |
| AAC | .aac | Apple ecosystem, efficient |
| M4A | .m4a | iTunes, Apple Music |
import { convert } from "peasy-audio";
// Convert MP3 to WAV for editing
const wav = await convert("music.mp3", { format: "wav" });
// Convert to FLAC with custom sample rate
const flac = await convert("music.mp3", {
format: "flac",
sampleRate: 48000,
});
// Downmix stereo to mono
const mono = await convert("stereo.wav", {
format: "mp3",
channels: 1,
bitrate: "128k",
});Learn more: Audio Format Comparison · Lossless vs Lossy Audio · What is an Audio Codec?
Trimming & Merging
Audio trimming extracts a segment by specifying start time and duration or end time. Merging concatenates multiple audio files sequentially into a single output file.
import { trim, merge } from "peasy-audio";
// Extract a 30-second segment starting at 1 minute
const clip = await trim("podcast.mp3", { start: 60, duration: 30 });
// Trim from start to end time
const intro = await trim("song.mp3", { start: 0, end: 15 });
// Merge multiple files into one
const combined = await merge([
"chapter1.mp3",
"chapter2.mp3",
"chapter3.mp3",
]);Learn more: How to Trim & Edit Audio in Browser · What is Clipping? · What is Decibel?
Volume & Normalization
Audio normalization adjusts the overall volume level to a target loudness, measured in dBFS (decibels relative to full scale). The EBU R128 standard defines target loudness at -23 LUFS for broadcast, while streaming platforms typically target -14 LUFS.
import { normalize, changeVolume } from "peasy-audio";
// Normalize volume using FFmpeg loudnorm filter
const normalized = await normalize("quiet-recording.mp3");
// Increase volume by 6dB (roughly doubles perceived loudness)
const louder = await changeVolume("track.mp3", { change: 6 });
// Decrease volume by 3dB
const softer = await changeVolume("loud-track.mp3", { change: -3 });Learn more: Audio Bitrate & Quality Guide · What is Normalize? · What is Dynamic Range?
Audio Effects
Apply fade effects, speed changes, reversal, and generate silence programmatically. These operations use FFmpeg audio filters for sample-accurate processing.
import { fade, speed, reverseAudio, silence } from "peasy-audio";
// Apply 3-second fade in and 5-second fade out
const faded = await fade("song.mp3", { fadeIn: 3, fadeOut: 5 });
// Double the playback speed (pitch shifts)
const fast = await speed("podcast.mp3", { factor: 2.0 });
// Slow down to 75% speed
const slow = await speed("audiobook.mp3", { factor: 0.75 });
// Reverse audio
const reversed = await reverseAudio("sample.mp3");
// Generate 5 seconds of silence as WAV
const gap = await silence({ duration: 5, format: "wav", sampleRate: 44100 });Learn more: Podcast Audio Quality Best Practices · What is Reverb? · What is Frequency?
TypeScript Types
import type {
AudioFormat,
AudioInfo,
ConvertOptions,
TrimOptions,
FadeOptions,
SpeedOptions,
VolumeOptions,
SilenceOptions,
} from "peasy-audio";
// AudioFormat — "mp3" | "wav" | "ogg" | "flac" | "aac" | "m4a"
const format: AudioFormat = "mp3";
// AudioInfo — metadata from info()
const meta: AudioInfo = {
duration: 240.5,
format: "mp3",
sampleRate: 44100,
channels: 2,
bitrate: 320000,
size: 9_600_000,
};API Reference
| Function | Description |
|----------|-------------|
| info(input) | Get audio metadata (duration, format, sample rate, channels, bitrate) |
| convert(input, options) | Convert between audio formats (MP3, WAV, OGG, FLAC, AAC, M4A) |
| trim(input, options) | Extract a segment by start/end/duration |
| merge(inputs) | Concatenate multiple audio files sequentially |
| normalize(input) | Normalize volume using EBU R128 loudnorm filter |
| changeVolume(input, options) | Adjust volume by dB amount |
| fade(input, options) | Apply fade in/out effects |
| speed(input, options) | Change playback speed (0.5x to 4.0x) |
| reverseAudio(input) | Reverse audio playback |
| silence(options) | Generate silence of specified duration |
REST API Client
The API client connects to the PeasyAudio developer API for tool discovery and content.
import { PeasyAudioClient } from "peasy-audio";
const client = new PeasyAudioClient();
// List available tools
const tools = await client.listTools();
console.log(tools.results);
// Search across all content
const results = await client.search("trim");
console.log(results);
// Browse the glossary
const glossary = await client.listGlossary({ search: "format" });
for (const term of glossary.results) {
console.log(`${term.term}: ${term.definition}`);
}
// Discover guides
const guides = await client.listGuides({ category: "audio" });
for (const guide of guides.results) {
console.log(`${guide.title} (${guide.audience_level})`);
}Full API documentation at peasyaudio.com/developers/.
Learn More
- Tools: Audio BPM Calculator · Audio Frequency Calculator · Audio Delay Calculator · Audio dB Calculator · Audio File Size Calculator · Audio Loudness Calculator · All Audio Tools
- Guides: Audio Format Comparison · Lossless vs Lossy Audio · Audio Bitrate & Quality Guide · Audio Format Guide: MP3, AAC, FLAC, WAV, OGG · Podcast Audio Quality Best Practices · How to Convert Between Audio Formats · All Guides
- Glossary: Sample Rate · Bitrate · Audio Codec · Decibel · Normalize · Dynamic Range · Clipping · PCM · All Terms
- Formats: MP3 · WAV · FLAC · OGG · AAC · All Formats
- API: REST API Docs · OpenAPI Spec
Also Available
| Language | Package | Install |
|----------|---------|---------|
| Python | peasy-audio | pip install "peasy-audio[all]" |
| Go | peasy-audio-go | go get github.com/peasytools/peasy-audio-go |
| Rust | peasy-audio | cargo add peasy-audio |
| Ruby | peasy-audio | gem install peasy-audio |
Peasy Developer Tools
Part of the Peasy Tools open-source developer ecosystem.
| Package | PyPI | npm | Description | |---------|------|-----|-------------| | peasy-pdf | PyPI | npm | PDF merge, split, rotate, compress, 21 operations — peasypdf.com | | peasy-image | PyPI | npm | Image resize, crop, convert, compress — peasyimage.com | | peasy-audio | PyPI | npm | Audio trim, merge, convert, normalize — peasyaudio.com | | peasy-video | PyPI | npm | Video trim, resize, thumbnails, GIF — peasyvideo.com | | peasy-css | PyPI | npm | CSS minify, format, analyze — peasycss.com | | peasy-compress | PyPI | npm | ZIP, TAR, gzip compression — peasytools.com | | peasy-document | PyPI | npm | Markdown, HTML, CSV, JSON conversion — peasyformats.com | | peasytext | PyPI | npm | Text case conversion, slugify, word count — peasytext.com |
License
MIT
