Base64 encode/decode · Guide
Decode Base64 Audio: Playing Encoded Sound in the Browser
Audio arrives Base64-encoded from text-to-speech APIs, voice message endpoints and JSON-only integrations. Playing it takes a few lines, but the choice between a data URI and a Blob decides whether it works for a two-second beep or a ten-minute recording.
The quick way, and its limit
For a short clip, a data URI assigned to an audio element is the shortest path:
const audio = new Audio('data:audio/mpeg;base64,' + b64);
audio.play();This falls over on longer audio: browsers cap data URI length, the entire string sits in memory as text, and seeking is unreliable. Treat it as suitable for notification sounds only.
Blob URLs for real audio
Decode to bytes and let the browser stream from a Blob, which supports seeking and has no practical size limit:
function playBase64Audio(b64, mime = 'audio/mpeg') {
const bytes = Uint8Array.from(atob(b64), (c) => c.charCodeAt(0));
const url = URL.createObjectURL(new Blob([bytes], { type: mime }));
const audio = new Audio(url);
audio.addEventListener('ended', () => URL.revokeObjectURL(url));
return audio.play();
}Revoke the object URL when playback finishes, or every clip leaks memory for the lifetime of the page.
Getting the MIME type right
audio/mpeg for MP3, audio/wav for WAV, audio/ogg for OGG, audio/mp4 or audio/aac for AAC, audio/webm for WebM. A wrong type is the usual reason audio silently refuses to play with no error in the console.
If you are unsure what you have, decode and check the first bytes: ID3 or FF FB is MP3, RIFF is WAV, OggS is OGG.
Autoplay
Browsers block audio that starts without user interaction. play() returns a promise that rejects with NotAllowedError — handle it rather than letting it surface as an unhandled rejection.
Start playback from a click handler, or mute the element first if it must begin automatically.
Frequently asked questions
Why does nothing play and no error appears?
Usually a wrong MIME type, or autoplay was blocked. Check the promise returned by play().
Data URI or Blob URL?
Blob for anything beyond a very short clip — it streams, supports seeking, and has no length cap.
How much larger is Base64 audio?
About 33%, so a 5 MB MP3 becomes roughly 6.7 MB of text.
Ready to try it?
Open the free browser-based Base64 encode/decode and apply what you just read — no sign-up, runs locally.
Open the Base64 encode/decode tool