0

Python 3.6.9 Flask 1.1.1 Werkzeug 0.16.0

on an POST call, I am sending a .wav file from postman. I am receiving that file on Flask by using the below lines

length = request.headers["Content-Length"]
Binaryfile = request.get_data(length)

My Binaryfile will look like this RIFFzuWAVEfmt >}dataVu ???someRandomData

Now, I need to read this data through python and need to send it into

import speech_recognition as sr
audioFile = sr.AudioFile(here, need a file-like object created from binary)
Phani
  • 92
  • 7

1 Answers1

0

What you want is io.BytesIO:

import io

Binaryfile = request.get_data(length)
file = io.BytesIO(Binaryfile)
audioFile = sr.audioFile(file)
Marco Bonelli
  • 63,369
  • 21
  • 118
  • 128
  • --SOLVED-- @Marco Bonelli, Thank you for your response. I tried passing file directly into sr.audioFile(), but I am facing the below error "Audio file could not be read as PCM WAV, AIFF/AIFF-C, or Native FLAC; check if file is corrupted or in another format" hence, I have created a .wav file in my local folder from file.read() method, and passed it's path into audioFile = sr.audioFile(audio file path) it works :) Thank you – Phani Jan 17 '20 at 13:37