Modern ES Module examples for integrating with the Tonn API using Node.js.
- Node.js 18+ (uses native fetch)
- Tonn API key (Get one here)
# 1. Install dependencies
npm install
# 2. Set your API key
export TONN_API_KEY=your_api_key_here
# 3. Run an example
node src/examples/01_mix_analysis.js your_track.wav POP| Script | Description |
|---|---|
01_mix_analysis.js |
Analyze a mix for technical issues |
02_mix_comparison.js |
Compare two mixes side-by-side |
03_mix_enhance.js |
Auto-enhance a stereo mix |
04_multitrack_mix.js |
Mix stems into a final track |
05_audio_cleanup.js |
Remove noise/hum/clicks |
06_batch_mastering.js |
Master multiple tracks for an album |
npm run example:analysis # Mix analysis
npm run example:comparison # Compare mixes
npm run example:enhance # Mix enhancement
npm run example:multitrack # Multitrack mixing
npm run example:cleanup # Audio cleanup
npm run example:mastering # Batch mastering# Analyze a mix
node src/examples/01_mix_analysis.js track.wav POP
# Analyze a master
node src/examples/01_mix_analysis.js master.wav ROCK --is-masternode src/examples/02_mix_comparison.js my_mix.wav reference.wav POP# Use demo track
node src/examples/03_mix_enhance.js
# Or provide your own URL
node src/examples/03_mix_enhance.js https://example.com/track.mp3# Uses default payload
node src/examples/04_multitrack_mix.js
# Or specify custom payload
node src/examples/04_multitrack_mix.js payloads/multitrack_mix.jsonnode src/examples/05_audio_cleanup.js noisy_recording.wav# Uses default payload
node src/examples/06_batch_mastering.js
# Or specify custom payload
node src/examples/06_batch_mastering.js payloads/album_mastering.jsonnodejs/
├── package.json # Dependencies and scripts
├── payloads/ # Example JSON payloads
│ ├── album_mastering.json
│ ├── final_mix_settings.json
│ └── multitrack_mix.json
└── src/
├── shared/
│ ├── client.js # Shared API client
│ └── config.js # Configuration utilities
└── examples/
├── 01_mix_analysis.js
├── 02_mix_comparison.js
├── 03_mix_enhance.js
├── 04_multitrack_mix.js
├── 05_audio_cleanup.js
└── 06_batch_mastering.js
The examples use a shared TonnClient class that handles common operations:
import { TonnClient } from '../shared/client.js';
const client = new TonnClient();
// Upload a file and get its URL
const url = await client.uploadLocalFile('track.wav');
// Make an API call
const response = await client.post('/mixanalysis', payload);
// Poll for async results
const result = await client.pollForResult({
endpoint: '/retrieveenhancedtrack',
payload: { mixReviveData: { mixReviveTaskId: taskId } },
resultKey: 'revivedTrackTaskResults',
maxAttempts: 30,
pollInterval: 5000
});
// Download a file
await client.downloadFile(url, 'output.wav');| Variable | Description |
|---|---|
TONN_API_KEY |
Your Tonn API key (required) |
You can also create a .env file:
TONN_API_KEY=your_api_key_here- MP3 (
.mp3) - WAV (
.wav) - FLAC (
.flac)
Make sure you've set the environment variable:
export TONN_API_KEY=your_api_key_here- Check the file path is correct
- Make sure the file exists
- Use absolute paths if needed
Some operations take time. The examples poll automatically, but for very long tasks you may need to increase maxAttempts in the polling options.
Make sure you're using Node.js 18 or later:
node --version # Should be v18.0.0 or higherSee the full Troubleshooting Guide.