I have audio recordings saved on a server as base64, webm format and want to decode them with python into a wav file. I tried both suggested ways from a simliar question found here: How to decode base64 String directly to binary audio format. But I'm facing different problems with both suggestions:
The version using file.write resulted in a wav file that I could play with the VLC player and which included the expected content. But I got an error message when I tried to read it with matlab or python saying "unknown format" or "missing riff".
fin = open(dirName + file, "r")
b64_str = fin.read()
fin.close()
# decode base64 string to original binary sound object
decodedData = base64.b64decode(b64_str)
webmfile = (outdir + file.split('.')[0] + ".webm")
wavfile = (outdir + file.split('.')[0] + ".wav")
with open(webmfile , 'wb') as wm:
wm.write(decodedData)
with open(webmfile, 'rb') as wm:
webmdata = pcm.read()
with open(wavfile, 'wb') as file:
file.write(webmdata)
The version using writeframes with setting the parameters result in a file I could read with matlab or python but this one does not contain the expected content and is way shorter than expected.
with wave.open(wavfile, 'wb') as wav:
wav.setparams((1, 2, 48000, 0, 'NONE', 'NONE'))
wav.writeframes(webmdata)
Any ideas on how to solve this problem? The file itself is fine. Converting it with an online converter worked.