Home Code How to convert base64 encoded text (audio / image) data into binary...

How to convert base64 encoded text (audio / image) data into binary (wav / mp3) file?

Base64 encoding is done to convert binary data in ASCII data. This makes it easy to embed binary data inside text files like HTML files, javascript, css files, etc. So you can send binary information like image data, audio data, mucic files etc as part of your HTML web page and javascript files.

Base64 decoding is the reverse process of converting Base64 encoded ASCII text back to the original binary form. In this article we will see how to convert Base64 encoded audio data in formats like wav or mp3 back to the original binary wav/mp3 file.

In fact, you can use the below methods to convert any base64 encoded data back to its binary format.

Step 1: Save the base64 encoded data into a text file

Copy ONLY the base64 data into text file and save it. Let us call the text file mybase64.txt

Please note that you should not copy any other encoding information like the example below. But only the actual Base64 content that is present after the below encoding information.

%MINIFYHTML219e2385c0df12f8b56cae2ad2493e1043%
data:audio/wav;base64,

Step 2: Convert Base 64 text to Binary File

Convert Base64 text to Binary File in Ubuntu or any Linux Platform

Use the below command base64 with the -d option to decode the base64 content back to binary content in Ubuntu or any other Linux distribution.

base64 mybase64.txt -d > myaudio.wav

Convert Base64 text to Binary File in Windows Platform

Use the windows command line tool Base64.exe with the -d option to decode the base64 content back to binary content in Windows Platform.

Base64.exe -d mybase64.txt > myaudio.wav

Convert Base64 text to Binary File in Mac OS X Platform

Use the command line tool base64 with the –decode option to decode the base64 content back to binary content in Apple Mac OS X.

base64 --decode mybase64.txt > myaudio.wav

Fix Base64 Decode Error

If you receive any error message while converting base64 to binary format, then first make sure you have copied ONLY the bas64 code and not any encoding information like data/audio etc.

Next, if you copied the base64 code from a HTML encoding, then most probably you have “=” of the base64 encoding replaced by its HTML equivalent “%3D”. You can see the %3D if present, at the end of the base64 text.

So replacing all ‘%3D’ with ‘=’ should fix your error. Do a simple string replace, in the language of your choice python or javascript as follows

content.replace("%3D","=");
Content Protection by DMCA.com
Gurudevhttps://www.hitxp.com
Gurudev is the developer of Gurunudi AI Platform. This is his official website where he pens his thoughts on a wide range of topics, answers queries, shares resources and tools developed by him.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

FacebookLike
InstagramFollow
PinterestFollow
RSS FeedSubscribe
Sound CloudFollow
TwitterFollow
YoutubeSubscribe

Latest Articles

Online Education should be interactive and innovative – Fun to Learn

For online education to succeed for smaller classses - it should be as interesting as cartoons. Online education cant succeed unless it is more interesting, interactive and innovative than offline schooling.

The Complete List of Dhatus – Sanskrit Root Words and their English meaning

A complete list of all dhatus (root words or verb roots) in Sanskrit dictionary and their meanings with corresponding IPA transliteration.

Sanskrit Lesson 4 – Word Creation Magic using Dhatus

Learn how easy it is to create new words in Sanskrit using root words called Dhatus. This simple process of Sanskrit grammar powers the entire language.

The Secret Role of Karma in Mahabharata

The seeds of Mahabharata were sown long back Duryodhana or Dhritarashtra were born. The story of Kaurvas and Pandavas is only the second half of the cycle of Karma. So what is the first half?

Latest Music Notations

So Gaya Ye Jahan – Tezaab – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song So Gaya Ye Jahan from the 1988 Hindi movie Tezaab in Western and Indian Notations.

Background Theme (BGM) – Mouna Ragam – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Background Theme (BGM) from the 1986 Tamil movie Mouna Ragam in Western and Indian Notations.

Dil Kya Kare Jab Kisi Se – Julie – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Dil Kya Kare Jab Kisi Se from the 1975 Hindi movie Julie in Western and Indian Notations.

Albela Sajan Aayo Re – Hum Dil De Chuke Sanam – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Albela Sajan Aayo Re from the 1999 Hindi movie Hum Dil De Chuke Sanam in Western and Indian Notations.
Content Protection by DMCA.com