How to convert WAV to Base64
- Drop a
.wavfile on the box or pick it with the file picker. - Play it in the preview.
- Output as is set to Data URI. For APIs choose Plain Base64, or JSON to include the name, MIME type and size.
- Press Copy output. Recordings of more than a few seconds are long strings; Save as .txt is easier to handle.
How big a Base64 WAV gets
Uncompressed PCM is easy to calculate: sample rate × bytes per sample × channels gives bytes per second. Add the standard 44-byte header and multiply by 4/3 for Base64:
| Format | 1 second | 10 seconds | 1 minute |
|---|---|---|---|
| 8 kHz, mono, 16-bit (telephone) | 21,392 chars | 213,392 chars | 1,280,060 chars |
| 16 kHz, mono, 16-bit (speech) | 42,728 chars | 426,728 chars | 2,560,060 chars |
| 44.1 kHz, mono, 16-bit | 117,660 chars | 1,176,060 chars | 7,056,060 chars |
| 44.1 kHz, stereo, 16-bit (CD) | 235,260 chars | 2,352,060 chars | 14,112,060 chars |
| 48 kHz, stereo, 16-bit | 256,060 chars | 2,560,060 chars | 15,360,060 chars |
Files recorded by some apps have extra chunks with metadata, so real sizes can be slightly larger.
WAV and speech APIs
Speech recognition services commonly accept uncompressed 16-bit PCM because it decodes without loss and needs no codec. When they take audio inline in a JSON request, it goes in as Base64, along with fields that describe the encoding, sample rate and channel count. Those values must match the file. A 44.1 kHz stereo recording declared as 16 kHz mono produces garbage transcripts or an error.
Speech models typically work at 16 kHz mono or lower. Converting a CD-quality stereo recording to 16 kHz mono before encoding makes the request about five and a half times smaller, usually without hurting recognition. Do it in an audio editor or with a command-line converter; this page encodes the file as it is.
If the inline limit is still too small for a long recording, these services usually also accept a link to a file in storage, which avoids Base64 entirely.
Generate a WAV and encode it in Python
The standard library can write a WAV and encode it, which is handy for test fixtures. This makes a 200 ms beep at 880 Hz:
import base64, io, math, struct, wave
rate = 8000
samples = b"".join(
struct.pack("<h", int(12000 * math.sin(2 * math.pi * 880 * i / rate)))
for i in range(rate // 5)
)
buf = io.BytesIO()
with wave.open(buf, "wb") as w:
w.setnchannels(1)
w.setsampwidth(2)
w.setframerate(rate)
w.writeframes(samples)
uri = "data:audio/wav;base64," + base64.b64encode(buf.getvalue()).decode()
The file is 3,244 bytes and the data URI 4,350 characters, starting data:audio/wav;base64,UklGRqQMAABXQVZF. More on files and streams in Base64 in Python.
Going back
Base64 to WAV plays a Base64 WAV string and saves it as a file. To shrink audio for the web, use a compressed format; see MP3 to Base64 for size comparisons.
FAQ
Why is my WAV Base64 so long?
WAV usually stores raw PCM samples with no compression. One second of CD-quality stereo is 176,400 bytes of audio, or 235,260 characters of Base64 including the header. Converting to mono and a lower sample rate cuts that a lot.
Is it audio/wav or audio/x-wav?
Both are in use and browsers play either. audio/wav is the common choice; some older systems send audio/x-wav or audio/wave. The tool uses the type your browser reports.
What do the first characters of a WAV in Base64 mean?
UklGR is the RIFF container header, shared with WebP and AVI. The WAVE tag shows up as XQVZF at characters 12 to 16, and Zm10 right after it is the fmt chunk.