Convert Audio Files to Base64
Base64 encoding transforms audio files into text strings for embedding in HTML, storing in databases, sending through APIs, or including in configuration files. This tool reads audio files locally and outputs Base64 strings in your chosen format.
How to Use
- Drop an audio file (MP3, WAV, OGG, FLAC, M4A, WebM) onto the upload area
- The tool reads the file in your browser and encodes it
- Choose output format: plain Base64, data URI, or CSS background (rarely used for audio)
- Copy the result
Embedding Audio in HTML
Inline audio element
<audio controls>
<source src="data:audio/mpeg;base64,SUQzBAAAAAAAI1..." type="audio/mpeg" />
</audio>
The browser creates an audio player that loads its data from the data URI. No external file request is made. This is useful for:
- Short notification sounds (under 50 KB)
- Sound effects in web games
- Audio in single file HTML exports
- Offline capable web applications
JavaScript Audio API
const audio = new Audio('data:audio/mpeg;base64,SUQzBAAAAAAAI1...');
audio.play();
This programmatically creates and plays an audio element from Base64 data. Web games and interactive applications use this pattern for sound effects that need instant playback without network latency.
Audio Formats and Base64 Sizes
| Format | Compression | 5 sec clip | 1 min clip | Base64 overhead |
|---|---|---|---|---|
| MP3 (128 kbps) | Lossy | ~80 KB | ~960 KB | +33% |
| MP3 (320 kbps) | Lossy | ~200 KB | ~2.4 MB | +33% |
| OGG Vorbis (128 kbps) | Lossy | ~65 KB | ~780 KB | +33% |
| WAV (16-bit 44.1 kHz) | None | ~440 KB | ~5.3 MB | +33% |
| FLAC | Lossless | ~220 KB | ~2.7 MB | +33% |
| AAC/M4A (128 kbps) | Lossy | ~75 KB | ~900 KB | +33% |
For Base64 embedding, MP3 and OGG offer the best file sizes. WAV is impractical for embedding due to its uncompressed size. FLAC is lossless but large. Choose the format based on your quality requirements and browser support needs.
Browser Audio Format Support
| Format | Chrome | Firefox | Safari | Edge |
|---|---|---|---|---|
| MP3 | Yes | Yes | Yes | Yes |
| OGG Vorbis | Yes | Yes | No | Yes |
| WAV | Yes | Yes | Yes | Yes |
| AAC/M4A | Yes | Yes | Yes | Yes |
| FLAC | Yes | Yes | Yes | Yes |
| WebM (Opus) | Yes | Yes | No | Yes |
MP3 has universal support. OGG and WebM are not supported in Safari. For maximum compatibility, MP3 is the safest choice for Base64 embedded audio.
Use Cases Beyond HTML Embedding
Text to speech API responses
TTS APIs (Google Cloud TTS, Amazon Polly, ElevenLabs) return synthesized audio as Base64 strings in JSON:
{
"audioContent": "SUQzBAAAAAAAI1RT..."
}
Decode the response to play it or save it. This tool lets you preview what the API returned.
Notification sounds in web apps
Progressive web apps can embed short notification sounds as Base64 constants in JavaScript, ensuring they work offline:
const NOTIFICATION_SOUND = 'data:audio/mpeg;base64,SUQzBAAAAAAAI1...';
function notify() {
new Audio(NOTIFICATION_SOUND).play();
}
Data URI in JSON configuration
Some application configurations include audio assets as Base64 strings for portability. This avoids managing separate audio files alongside configuration.
When Not to Base64 Encode Audio
Audio files get large quickly. General guidelines:
- Under 100 KB: embed as Base64 for instant playback
- 100 KB - 1 MB: consider tradeoffs (convenience vs. page size)
- Over 1 MB: serve as a separate file with streaming
For music or long recordings, use standard <audio> elements with src pointing to a URL. Base64 embedding forces the entire file to load before playback can begin, while regular audio files support streaming (play while downloading).
For image encoding, see Image to Base64. For document encoding, see PDF to Base64. For text encoding, the main Base64 Encoder handles that.