Flask Audio File to Wave Object Python

Viewed 574

I want to convert an audio file received from flask api (of type class 'werkzeug.datastructures.FileStorage') to a Wave (https://pypi.org/project/Wave/) object. Usually, you do this by supplying a path on your comp:

import wave
wav = wave.open("test.wav", "r")

But this doesn't work as I do not want to save the audio file to my computer. This is how I get the audio file in my flask script:

audio = request.files["audio"]

Please let me know what I can do! Thanks.

2 Answers

You can try the following modification of your code:

audio = request.files['audio_file']

The request.files is a dictionary. The dictionary key that will allow you to retrieve the audio file is 'audio_file' instead of 'audio'.

Related