Audio file is sent to us via API which is Base64 encoded PCM format. I need to convert it to PCM and then WAV for processing.
I was able to decode -> save to pcm -> read from pcm -> save as wav using the following code.
decoded_data = base64.b64decode(data, ' /')
with open(pcmfile, 'wb') as pcm:
    pcm.write(decoded_data)
with open(pcmfile, 'rb') as pcm:
    pcmdata = pcm.read()
with wave.open(wavfile, 'wb') as wav:
    wav.setparams((1, 2, 16000, 0, 'NONE', 'NONE'))
    wav.writeframes(pcmdata)
It'd be a lot easier if I could just decode the input string to binary and save as wav. So I did something like this in Convert string to binary in python
  decoded_data = base64.b64decode(data, ' /')
    ba = ' '.join(format(x, 'b') for x in bytearray(decoded_data))
    with wave.open(wavfile, 'wb') as wav:
        wav.setparams((1, 2, 16000, 0, 'NONE', 'NONE'))
        wav.writeframes(ba)
But I got error a bytes-like object is required, not 'str' at wav.writeframes. 
Also tried base54.decodebytes() and got the same error.
What is the correct way to do this?
 
     
    