Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

167
Vistas
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.

def read_wave(self, path: str) -> Dict:
   with contextlib.closing(wave.open(path, "rb")) as wf:

     num_channels: int = wf.getnchannels()
     assert num_channels == 1
     sample_width: int = wf.getsampwidth()
     assert sample_width == 2
     sample_rate: int = wf.getframerate()
     assert sample_rate in (8000, 16000, 32000)
     frames: int = wf.getnframes()
     pcm_data: bytes = wf.readframes(frames)
     duration: float = frames / sample_rate

     return {
          "pcm_data": pcm_data,
          "sample_rate": sample_rate,
          "duration": duration,
     }

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.

@app.post(path="/upload-audios/")
async def upload_audios(audios: list[UploadFile] = File(...)):
   pass

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

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

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda