MP3 to Base64 for embedded sound
The MP3 to Base64 converter encodes an audio file as text so it can be embedded in HTML, JavaScript or JSON. With the Data URI output you get data:audio/mpeg;base64,…, which works directly as the src of an <audio> element or with the JavaScript Audio constructor. A preview player lets you confirm the encoded audio plays correctly.
Using the output
<audio controls src="data:audio/mpeg;base64,SUQzBAAAAAAA…"></audio>
new Audio("data:audio/mpeg;base64,SUQzBAAAAAAA…").play();MP3 files that begin with an ID3 metadata tag start with the bytes ID3, which is why their Base64 usually begins with SUQz. Files without a tag start with an MPEG frame header instead (often // in Base64).
Playing embedded clips with the Web Audio API
An <audio> element is fine for occasional sounds, but games and interactive apps usually decode clips once into an AudioBuffer so they can play instantly and overlap. Use the Raw Base64 output:
const bytes = Uint8Array.from(atob(clip), (c) => c.charCodeAt(0));
const buffer = await audioCtx.decodeAudioData(bytes.buffer);
const source = audioCtx.createBufferSource();
source.buffer = buffer;
source.connect(audioCtx.destination);
source.start();
To predict the size before encoding, multiply the bitrate by the duration: a 3-second effect at 64 kbps is 64,000 ÷ 8 × 3 = 24,000 bytes, which grows to about 32 KB as Base64. That is a reasonable cost for a sound the app needs immediately.
Good use cases
- Short UI sounds — clicks, notifications, success chimes — bundled in a web app or browser extension without extra files.
- Games and single-file demos that must run offline or from one HTML file.
- Speech and audio APIs that accept audio clips as Base64 in a JSON body.
- Test fixtures for audio-processing code.
Size considerations
Audio adds up quickly: one minute of 128 kbps MP3 is roughly 1 MB, or about 1.3 MB as Base64. Embedding long tracks makes pages and scripts slow to load and prevents the browser from streaming or caching the audio separately. Keep embedded clips to a few seconds, lower the bitrate for effects (64 kbps mono is often enough), and serve music or podcasts as normal files.
Autoplay rules
Browsers block audio from playing automatically until the user has interacted with the page, whether the source is a file or a data URI. Trigger play() from a click or key press, and handle the promise it returns so a blocked attempt does not cause an unhandled error.
Other audio formats
The tool is designed for MP3, the most widely supported audio format. For other file types — WAV, OGG, fonts or documents — use File to Base64, which accepts anything and picks the MIME type from the file. To check the start of an encoded file, Base64 to Hex shows its first bytes. As with images, only embed audio you have the right to use.
The file is read and encoded locally in your browser; it is never uploaded.