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

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.

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.

Latest Music Notations

Kempadavo Ella Kempadavo – Ellindalo Bandavaru – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Kempadavo Ella Kempadavo from the 1980 Kannada movie Ellindalo Bandavaru in Western and Indian Notations.

Bella Ciao – Money Heist (La casa de papel) – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Bella Ciao from the 2018 Spanish Web Series Money Heist (La casa de papel) in Western and Indian Notations.

Haule Haule – Rab Ne Banadi Jodi – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Haule Haule from the 2008 Hindi movie Rab Ne Banadi Jodi in Western and Indian Notations.

Gori Tera Gaon Bada Pyara – Chitchor – Piano Notations

Piano, Keyboard, Violin, Flute notes, Guitar Tabs and Sheet Music of the Song Gori Tera Gaon Bada Pyara from the 1976 Hindi movie Chitchor in Western and Indian Notations.
Content Protection by DMCA.com