title: How to download audio base64 string as an mp3 file without corrupting it?
body: <p>I have a 10 second audio stream that is encoded as a base64 string. When attached to an audio tag, it plays properly inside the HTML element. On trying to download it, it downloads as a (corrupted?) file with a duration of 0:00.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>var audio = document.getElementById('audio-element');
  var linkTag = document.getElementById('link-element');
  
  linkTag.href = audio.src;
  linkTag.download = 'audio-file';
  linkTag.click();</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;!DOCTYPE html&gt;
  &lt;html&gt;
    &lt;head&gt;
        
    &lt;/head&gt;
    &lt;body&gt;
      &lt;audio src="data:audio/mp3; codecs=opus;base64,GkXfo59ChoEBQveBAULy.............IiT5Q==" controls id="audio-element"&gt;
        Your browser does not support the audio element
      &lt;/audio&gt;
      
      &lt;a href="" id="link-element"&gt;Download audio&lt;/a&gt;
    &lt;/body&gt;
  &lt;/html&gt;</code></pre>
  </div>
  </div>
  </p>
  
  <p>The base64 string in the code snippet above is invalid, because going over the 30,000 character limit is not allowed in questions. Consequently, I had to trim it down. The original string is valid and plays fine, but can't be posted here because of the character limit.</p>
  
  <p>What I want is for an accurate mp3 file to be downloaded from a base64 encoded string of type 'audio/mp3'.</p>
  
  <p>How do I do this using plain javascript / ES6? Insights would be greatly appreciated.</p>