Base64 to Audio Converter

Free online tool to decode Base64 strings and convert them back to audio files. Supports MP3, WAV, OGG, FLAC, and other formats. Instant preview and download.

Why Use Base64 to Audio Converter?

Instant Preview

Play and preview the decoded audio before downloading

Auto Format Detection

Automatically detects audio format from Base64 data

Secure & Private

All decoding happens in your browser. No data sent to servers.

One-Click Download

Download the decoded audio file with proper file extension

Implementation Examples

Learn how to convert Base64 strings back to audio files in your favorite programming language. All examples include complete, working code that you can use in your projects.

How to Convert Base64 to Audio with JavaScript

// Convert Base64 to audio and play
function base64ToAudio(base64String) {
  // Remove data URL prefix if present
  const base64 = base64String.replace(/^data:audio\/[a-z]+;base64,/, '');

  // Decode Base64 to binary
  const binaryString = atob(base64);
  const bytes = new Uint8Array(binaryString.length);

  for (let i = 0; i < binaryString.length; i++) {
    bytes[i] = binaryString.charCodeAt(i);
  }

  // Create blob and audio element
  const blob = new Blob([bytes], { type: 'audio/mpeg' });
  const url = URL.createObjectURL(blob);

  const audio = new Audio(url);
  audio.play();

  return { audio, url };
}

// Download Base64 as audio file
function downloadBase64Audio(base64String, filename = 'audio.mp3') {
  const base64 = base64String.replace(/^data:audio\/[a-z]+;base64,/, '');
  const binaryString = atob(base64);
  const bytes = new Uint8Array(binaryString.length);

  for (let i = 0; i < binaryString.length; i++) {
    bytes[i] = binaryString.charCodeAt(i);
  }

  const blob = new Blob([bytes], { type: 'audio/mpeg' });
  const url = URL.createObjectURL(blob);

  const a = document.createElement('a');
  a.href = url;
  a.download = filename;
  a.click();

  URL.revokeObjectURL(url);
}

How to Convert Base64 to Audio with Python

import base64

# Convert Base64 to audio file
def base64_to_audio(base64_string, output_path):
    # Remove data URL prefix if present
    if 'base64,' in base64_string:
        base64_string = base64_string.split('base64,')[1]

    # Decode and save
    audio_data = base64.b64decode(base64_string)

    with open(output_path, 'wb') as audio_file:
        audio_file.write(audio_data)

    print(f"Audio saved to {output_path}")

# Usage
base64_string = "//uQxAA..."  # Your Base64 string
base64_to_audio(base64_string, "output.mp3")

# From JSON API response
import json
import requests

response = requests.get('https://api.example.com/audio')
data = response.json()

base64_audio = data['audio']
base64_to_audio(base64_audio, "downloaded_audio.mp3")

# Verify audio file
from mutagen.mp3 import MP3

audio = MP3("output.mp3")
print(f"Duration: {audio.info.length} seconds")
print(f"Bitrate: {audio.info.bitrate} bps")

How to Convert Base64 to Audio with PHP

<?php
// Convert Base64 to audio file
function base64ToAudio($base64String, $outputPath) {
    // Remove data URL prefix if present
    if (strpos($base64String, 'base64,') !== false) {
        $base64String = explode('base64,', $base64String)[1];
    }

    // Decode and save
    $audioData = base64_decode($base64String);
    file_put_contents($outputPath, $audioData);

    echo "Audio saved to $outputPath\n";
}

// Usage
$base64String = "//uQxAA..."; // Your Base64 string
base64ToAudio($base64String, "output.mp3");

// From API response
$response = file_get_contents('https://api.example.com/audio');
$data = json_decode($response, true);

base64ToAudio($data['audio'], "downloaded_audio.mp3");

// Stream audio to browser
header('Content-Type: audio/mpeg');
header('Content-Disposition: attachment; filename="audio.mp3"');

$base64 = $_POST['base64'];
echo base64_decode($base64);
?>

How to Convert Base64 to Audio with Node.js

const fs = require('fs').promises;

// Convert Base64 to audio file
async function base64ToAudio(base64String, outputPath) {
  // Remove data URL prefix if present
  const base64 = base64String.replace(/^data:audio\/[a-z]+;base64,/, '');

  // Decode and save
  const buffer = Buffer.from(base64, 'base64');
  await fs.writeFile(outputPath, buffer);

  console.log(`Audio saved to ${outputPath}`);
}

// Usage
const base64String = "//uQxAA..."; // Your Base64 string
await base64ToAudio(base64String, 'output.mp3');

// Express.js API endpoint
const express = require('express');
const app = express();

app.post('/api/audio/decode', express.json(), async (req, res) => {
  const { base64, filename = 'audio.mp3' } = req.body;

  try {
    const buffer = Buffer.from(base64, 'base64');

    // Send as download
    res.setHeader('Content-Type', 'audio/mpeg');
    res.setHeader('Content-Disposition', `attachment; filename="${filename}"`);
    res.send(buffer);
  } catch (error) {
    res.status(400).json({ error: 'Invalid Base64 string' });
  }
});

// Stream large audio files
const stream = require('stream');

app.get('/api/audio/stream/:id', async (req, res) => {
  const base64 = await getAudioBase64(req.params.id);
  const buffer = Buffer.from(base64, 'base64');

  const readStream = stream.Readable.from(buffer);

  res.setHeader('Content-Type', 'audio/mpeg');
  readStream.pipe(res);
});

Share this tool

Help others discover this free Base64 tool

or