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.

data:audio/wav;base64,
Code language: Bash (bash)

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
Code language: Bash (bash)

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
Code language: Bash (bash)

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
Code language: Bash (bash)

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","=");
Code language: JavaScript (javascript)
Content Protection by DMCA.com

Download HitXP Mobile App

Get it on Google Play
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

How does GOD helps us?

Do prayers really help? Do miracles happen when we are in trouble? Does God really help us in times of need? Are prayers enough to save us during bad times? How should we face problems?

Sanskrit poem on Ramayana – read in reverse becomes Mahabharata!

A Sanskrit poem about Ramayana when read in reverse direction becomes a poem on Mahabharata!

The difference between Itihasa and Puranas

Documentation of ancient Indian history and the historical events of Indian civilization in the form of Itihasa and Puranas - Ramayana and Mahabharata.

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.

Latest Music Notations

Oo Antava Mava – Pushpa – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Oo Antava Mava from the 2022 Telugu movie Pushpa in Western and Indian Notations.

Kaa Chalige Bangalore (Tiningaa Miningaa Tishaaaa) – Salaga – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Tiningaa Miningaa Tishaaaa (Kaa Chali Ge) from the 2022 Kannada movie Salaga in Western and Indian Notations.

Title Track BGM – Irul – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Title Track BGM from the 2021 Malayalam movie Irul in Western and Indian Notations.

Ninnukori Varnam – Agni Natchathiram – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Ninnukori Varnam from the 1988 Tamil movie Agni Natchathiram in Western and Indian Notations.
Content Protection by DMCA.com