How to base64 decode on Windows 10 without base64.exe

Converting the base64 audio content response from the Google Cloud Text-to-Speech API into a playable file on windows using PowerShell.

2 minute read

TL;DR

You can call certutil from PowerShell to produce the required file.

Introduction

There is a moment in life where you get stuck in a quick start guide - we’ve all been there. At the start of my Google Cloud text-to-speech project it arrived quickly and unexpectedly at step two of this two-step quick start guide.

I had successfully returned my first base64 encoded speech audio, onward to the last step:

“Decode the source text file using the Base64.exe tool:”

'base64.exe' is not recognized as an internal or external command, operable program or batch file.

Of course, it wasn’t. Let’s put that dance for joy on ice for now.

How did we get here?

As I was interacting with the API via PowerShell I was looking for a native local solution that PowerShell could invoke upon response. Additionally, it would be useful to be able to re-invoke as part of some future test scripts.

Whilst I can’t recall the precise StackOverflow post that set me on this path - I’ll give credit to this one.

Here is the code snippet I used to create time stamped audio files:

$base64Audio | Out-File -FilePath "./google.txt" -Encoding ascii -Force
$convertedFileName = 'Converted-{0}.mpga' -f (get-date -f yyyy-MM-dd-hh-mm-ss)
certutil -decode google.txt $convertedFileName

This image always comes to mind when step by step guides break down:

Alt Text

Author of image: Van Oktop