Skip to content
Advertisement

How to get wave module methods for reading a .wav audio but with a temporary file tempfile.SpooledTemporaryFile obtained from fastAPI post request?

I have a function that receives a .wav audio path directory and return its pcm_data in bytes, sample_rate as int and duration as float.

JavaScript

Now I want that the audio file comes from a uploaded audio using POST request with FastAPI, so if I upload a .wav audio using the UploadFile class from fastapi, I get a tempfile.SpooledTemporaryFile, how can I adapt the first function for this case.

JavaScript

Advertisement

Answer

The wave.open function supports a file like object, so you can use the .file attribute of UploadFile directly (it represents the SpooledTemporaryFile instance).

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement