stacks/ts-audio
publicClone
Push over the same URL. A password will not work: create a token under access tokens and use it in place of one.
- .github
- .vscode
- docs
- packages
- .editorconfig 147 B
- .gitattributes 12 B
- .gitignore 173 B
- buddy-bot.config.ts 854 B
- bun.lock 37.2 KB
- bunfig.toml 107 B
- CHANGELOG.md 51.3 KB
- clarity.config.ts 133 B
- CLAUDE.md 1.4 KB
- deps.yaml 32 B
- LICENSE.md 1.1 KB
- package.json 2.0 KB
- pkgx.yaml 53 B
- README.md 8.2 KB
- tsconfig.json 1.0 KB

audiox
A TypeScript-based audio processing library & CLI that wraps ffmpeg, helping you optimize audio files in Node.js/Bun environments.
Features
- Audio optimizations and conversions
- Stream-based processing support
- Metadata handling
- Multiple output formats (WAV, MP3, AAC)
- Configurable audio properties (bitrate, channels, sample rate)
- Error handling and detailed logging
- Fully typed with TypeScript
Install
bun install @stacksjs/audioxGet Started
There are two ways of using this tool: as a library or as a CLI.
Library Usage
Given the npm package is installed:
import { audio, audioInfo } from '@stacksjs/audiox'
// Basic audio conversion
await audio('input.mp3', 'output.wav', {
codec: 'pcm_s16le',
channels: 1,
sampleRate: 16000,
bitrate: '160k',
})
// Get audio file information
const info = await audioInfo('audio.mp3')
console.log(info)
// [
// {
// codec: 'mp3',
// channels: 2,
// sampleRate: '44100',
// bitrate: '192000',
// duration: '180.5',
// }
// ]
// Convert with metadata
await audio('input.mp3', 'output.mp3', {
codec: 'mp3',
bitrate: '192k',
channels: 2,
sampleRate: 44100,
metadata: {
title: 'My Track',
artist: 'Artist Name',
album: 'Album Name',
year: '2024',
},
})
// Stream processing
const file = Bun.file('input.mp3')
const stream = file.stream()
await audioWithStreamInput(stream, 'output.wav', {
codec: 'pcm_s16le',
bitrate: '128k',
channels: 1,
sampleRate: 16000,
})
// Buffer processing
const arrayBuffer = await Bun.file('input.mp3').arrayBuffer()
const wavData = await audioWav(new Uint8Array(arrayBuffer))
await Bun.write('output.wav', wavData)CLI Usage
Once installed globally or locally in your project, you can use audiox from the command line:
# Global installation
npm install -g @stacksjs/audiox
# Using npx with local installation
npx audiox [command] [options]
# Using bun
bunx audiox [command] [options]Basic Commands
Convert audio files with default settings:
audiox convert input.mp3 output.wavGet audio file information:
audiox info input.mp3Convert Command Options
audiox convert <input> <output> [options]
Options:
--codec <codec> Audio codec (aac, mp3, pcm_s16le)
--bitrate <bitrate> Audio bitrate (e.g., "192k")
--channels <number> Number of channels (1, 2, 5.1, 7.1)
--sample-rate <rate> Sample rate (8000, 16000, 44100, 48000)
--quality <number> Audio quality setting
-m, --metadata <data> Set metadata (format: key=value)
-v, --verbose Enable verbose outputExamples
Convert to WAV with specific settings:
audiox convert input.mp3 output.wav --codec pcm_s16le --channels 1 --sample-rate 16000 --bitrate 128kConvert to MP3 with metadata:
audiox convert input.wav output.mp3 --codec mp3 --bitrate 192k \
--metadata title="My Song" \
--metadata artist="Artist Name" \
--metadata year=2024Get detailed audio information including metadata:
audiox info input.mp3 --metadata title,artist,album,yearConfiguration
You can create a audiox.config.js or audiox.config.ts file in your project root to set default options:
import type { AudioxOptions } from './src/types'
const config: AudioxOptions = {
codec: 'mp3',
bitrate: '192k',
channels: 2,
sampleRate: 44100,
verbose: true
}
export default configThe CLI will automatically use these defaults unless overridden by command-line options.
Advanced Usage
Stream Processing with Custom Handlers
// Process audio with stream output handling
await audioWithStreamOut(
'input.mp3',
{
onProcessDataFlushed: (chunk) => {
// Handle each chunk of processed audio
console.log('Processing chunk:', chunk?.length)
},
onProcessDataEnd: async (data) => {
// Handle completed audio data
await Bun.write('output.wav', data!)
},
},
{
codec: 'pcm_s16le',
bitrate: '128k',
channels: 1,
sampleRate: 16000,
},
)Detailed Audio Information
// Get audio information including metadata
const audioInfo = await audioInfo('music.mp3', {
metadataTags: ['title', 'artist', 'album', 'track', 'genre', 'year'],
})
// Example response:
// [
// {
// codec: 'mp3',
// channels: 2,
// sampleRate: '44100',
// bitrate: '192000',
// duration: '180.5',
// metadata: {
// title: 'Song Title',
// artist: 'Artist Name',
// album: 'Album Name',
// track: '1',
// genre: 'Pop',
// year: '2024'
// }
// }
// ]Configuration
Audiox can be configured using a audiox.config.ts (or audiox.config.js) file:
import type { AudioxConfig } from '@stacksjs/audiox'
const config: AudioxConfig = {
verbose: true, // Enable detailed logging
// Default audio settings
codec: 'mp3',
bitrate: '192k',
channels: 2,
sampleRate: 44100,
}
export default configAvailable Options
interface AudioxOptions {
codec?: 'aac' | 'mp3' | 'pcm_s16le' | string
bitrate?: string // e.g., "192k"
channels?: 1 | 2 | 5.1 | 7.1 | number
sampleRate?: 8000 | 16000 | 44100 | 48000 | number
quality?: number
metadata?: {
[key: string]: string
}
onError?: (error: unknown) => void
verbose: boolean
}Testing
bun testChangelog
Please see our releases page for more information on what has changed recently.
Contributing
Please review the Contributing Guide for details.
Community
For help, discussion about best practices, or any other conversation that would benefit from being searchable:
For casual chit-chat with others using this package:
Join the Stacks Discord Server
Postcardware
“Software that is free, but hopes for a postcard.” We love receiving postcards from around the world showing where audiox is being used! We showcase them on our website too.
Our address: Stacks.js, 12665 Village Ln #2306, Playa Vista, CA 90094 🌎
Sponsors
We would like to extend our thanks to the following sponsors for funding Stacks development. If you are interested in becoming a sponsor, please reach out to us.
Credits
License
The MIT License (MIT). Please see LICENSE for more information.
Made with 💙
[codecov-href]: https://codecov.io/gh/stacksjs/audiox -->