Extract Audio from Video Using API: Complete Tutorial 2026
Learn how to extract audio tracks from videos using a simple API. Complete guide with code examples, format options, and best practices for developers.
Extracting audio from video files is a common requirement for podcasts, music production, and content repurposing. This comprehensive guide shows you how to extract audio using a simple API, with support for multiple formats and quality settings.
Why Extract Audio from Video?
Common Scenarios
| Use Case | Example | Output Format |
|---|---|---|
| Podcasts | Extract interview audio | MP3 |
| Music | Get soundtrack from video | WAV, FLAC |
| Transcription | Extract speech for text | MP3, WAV |
| Remixing | Get audio for editing | WAV |
| Archival | Save audio separately | FLAC |
Benefits
- Reduce file size - Audio-only files are 90% smaller
- Repurpose content - Use audio across platforms
- Easy editing - Work with audio separately
- Better organization - Manage audio and video independently
API Integration Guide
Step 1: Basic Extraction
javascriptconst extractAudio = async (videoUrl) => { try { const response = await fetch('https://eranol.com/api/v1/extract/audio', { method: 'POST', headers: { 'x-api-key': process.env.ERANOL_API_KEY, 'Content-Type': 'application/json' }, body: JSON.stringify({ input_url: videoUrl, output_format: 'mp3' }) }); if (!response.ok) { throw new Error(`API Error: ${response.statusText}`); } const result = await response.json(); return result; } catch (error) { console.error('Audio extraction failed:', error); throw error; } }; // Extract audio as MP3 const job = await extractAudio('https://example.com/video.mp4');
Step 2: Choose Output Format
javascriptconst extractAudioWithFormat = async (videoUrl, format = 'mp3') => { const response = await fetch('https://eranol.com/api/v1/extract/audio', { method: 'POST', headers: { 'x-api-key': process.env.ERANOL_API_KEY, 'Content-Type': 'application/json' }, body: JSON.stringify({ input_url: videoUrl, output_format: format }) }); return await response.json(); }; // Extract as different formats const mp3Job = await extractAudioWithFormat(videoUrl, 'mp3'); const wavJob = await extractAudioWithFormat(videoUrl, 'wav'); const flacJob = await extractAudioWithFormat(videoUrl, 'flac');
Step 3: Customize Quality
javascriptconst extractHighQualityAudio = async (videoUrl, options = {}) => { const defaultOptions = { output_format: 'mp3', bitrate: '320k', sample_rate: 48000, channels: 2 }; const finalOptions = { ...defaultOptions, ...options }; const response = await fetch('https://eranol.com/api/v1/extract/audio', { method: 'POST', headers: { 'x-api-key': process.env.ERANOL_API_KEY, 'Content-Type': 'application/json' }, body: JSON.stringify({ input_url: videoUrl, ...finalOptions }) }); return await response.json(); }; // Extract high-quality audio const job = await extractHighQualityAudio(videoUrl, { bitrate: '320k', sample_rate: 48000 });
Format Comparison
Audio Format Guide
| Format | Quality | File Size | Use Case |
|---|---|---|---|
| MP3 | Good | Small | Podcasts, web |
| WAV | Lossless | Large | Editing, production |
| FLAC | Lossless | Medium | Archival, music |
| AAC | Excellent | Small | Apple devices |
| OGG | Good | Small | Open source |
Quality Settings
javascriptconst qualityPresets = { podcast: { output_format: 'mp3', bitrate: '128k', sample_rate: 44100, channels: 1 // Mono for voice }, music: { output_format: 'mp3', bitrate: '320k', sample_rate: 48000, channels: 2 // Stereo }, production: { output_format: 'wav', sample_rate: 48000, channels: 2, bit_depth: 24 }, archival: { output_format: 'flac', sample_rate: 96000, channels: 2 } }; const extractWithPreset = async (videoUrl, preset) => { const settings = qualityPresets[preset]; const response = await fetch('https://eranol.com/api/v1/extract/audio', { method: 'POST', headers: { 'x-api-key': process.env.ERANOL_API_KEY, 'Content-Type': 'application/json' }, body: JSON.stringify({ input_url: videoUrl, ...settings }) }); return await response.json(); }; // Extract audio optimized for podcasts const podcastAudio = await extractWithPreset(videoUrl, 'podcast');
Common Use Cases
1. Podcast Production
javascriptconst extractPodcastAudio = async (videoUrl, episodeData) => { const response = await fetch('https://eranol.com/api/v1/extract/audio', { method: 'POST', headers: { 'x-api-key': process.env.ERANOL_API_KEY, 'Content-Type': 'application/json' }, body: JSON.stringify({ input_url: videoUrl, output_format: 'mp3', bitrate: '192k', normalize: true, remove_silence: true, metadata: { title: episodeData.title, artist: episodeData.host, album: episodeData.podcastName } }) }); return await response.json(); };
2. Music Extraction
javascriptconst extractMusicTrack = async (videoUrl) => { const response = await fetch('https://eranol.com/api/v1/extract/audio', { method: 'POST', headers: { 'x-api-key': process.env.ERANOL_API_KEY, 'Content-Type': 'application/json' }, body: JSON.stringify({ input_url: videoUrl, output_format: 'flac', sample_rate: 96000, channels: 2 }) }); return await response.json(); };
3. Batch Extraction
javascriptconst batchExtractAudio = async (videoUrls, format = 'mp3') => { const jobs = await Promise.all( videoUrls.map(url => extractAudioWithFormat(url, format)) ); const results = await Promise.all( jobs.map(job => waitForCompletion(job.job_id)) ); return results; }; // Extract audio from multiple videos const videos = [ 'https://example.com/video1.mp4', 'https://example.com/video2.mp4', 'https://example.com/video3.mp4' ]; const audioFiles = await batchExtractAudio(videos, 'mp3');
Best Practices
1. Choose Appropriate Format
javascriptconst selectFormat = (useCase) => { const formats = { podcast: 'mp3', music: 'flac', editing: 'wav', web: 'mp3', mobile: 'aac' }; return formats[useCase] || 'mp3'; }; const format = selectFormat('podcast'); const job = await extractAudioWithFormat(videoUrl, format);
2. Optimize for File Size
javascriptconst extractOptimizedAudio = async (videoUrl) => { return await extractAudio(videoUrl, { output_format: 'mp3', bitrate: '128k', channels: 1, sample_rate: 44100 }); };
3. Preserve Quality
javascriptconst extractLosslessAudio = async (videoUrl) => { return await extractAudio(videoUrl, { output_format: 'flac', sample_rate: 96000, channels: 2 }); };
Real-World Implementation
javascriptclass AudioExtractor { constructor(apiKey) { this.apiKey = apiKey; this.baseUrl = 'https://eranol.com/api/v1'; } async extractAudio(videoUrl, options = {}) { const defaultOptions = { output_format: 'mp3', bitrate: '192k' }; const finalOptions = { ...defaultOptions, ...options }; const response = await fetch(`${this.baseUrl}/extract/audio`, { method: 'POST', headers: { 'x-api-key': this.apiKey, 'Content-Type': 'application/json' }, body: JSON.stringify({ input_url: videoUrl, ...finalOptions }) }); if (!response.ok) { throw new Error(`API Error: ${response.statusText}`); } const job = await response.json(); return await this.waitForCompletion(job.job_id); } async waitForCompletion(jobId) { const maxAttempts = 60; for (let i = 0; i < maxAttempts; i++) { const response = await fetch(`${this.baseUrl}/status/${jobId}`, { headers: { 'x-api-key': this.apiKey } }); const status = await response.json(); if (status.state === 'completed') { return status.output_url; } else if (status.state === 'failed') { throw new Error(`Extraction failed: ${status.error}`); } await this.sleep(3000); } throw new Error('Extraction timeout'); } sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); } } // Usage const extractor = new AudioExtractor(process.env.ERANOL_API_KEY); const audioUrl = await extractor.extractAudio('https://example.com/video.mp4', { output_format: 'mp3', bitrate: '320k', normalize: true }); console.log('Audio extracted:', audioUrl);
Cost Optimization
Format vs Cost
| Format | Cost per Minute | File Size |
|---|---|---|
| MP3 (128k) | $0.05 | ~1MB |
| MP3 (320k) | $0.07 | ~2.4MB |
| WAV | $0.10 | ~10MB |
| FLAC | $0.08 | ~5MB |
Troubleshooting
Issue 1: No Audio Track
Solution:
javascript// Check if video has audio const checkAudioTrack = async (videoUrl) => { try { const job = await extractAudio(videoUrl); return true; } catch (error) { if (error.message.includes('no audio')) { console.log('Video has no audio track'); return false; } throw error; } };
Issue 2: Poor Quality
Solution:
javascript// Extract with maximum quality const job = await extractAudio(videoUrl, { output_format: 'wav', sample_rate: 48000, bit_depth: 24 });
Conclusion
Extracting audio from videos using an API is simple and efficient:
✅ Multiple formats - MP3, WAV, FLAC, AAC ✅ Quality control - Customize bitrate and sample rate ✅ Fast processing - Results in seconds ✅ Batch support - Process multiple videos ✅ Cost-effective - Pay per extraction
Ready to extract audio? Try Eranol's Audio Extraction API with $1 free credit.
Related Articles:
Related Articles
How to Convert Video to MP4 Using API: Complete Guide 2026
Learn how to convert any video format to MP4 using a simple API. Complete tutorial with code examples, best practices, and real-world use cases for developers.
Read more →Convert Audio to MP3 with API: Developer's Guide 2026
Complete guide to converting audio files to MP3 format using a simple API. Learn best practices, code examples, and optimization techniques for developers.
Read more →Convert Video to GIF Using API: Complete Guide 2026
Learn how to convert videos to animated GIFs using a simple API. Complete tutorial with optimization techniques, code examples, and best practices for developers.
Read more →