How To Send Audio Files To Flask API Using Postman?

Hello Learners…

Welcome to my blog…

Here we learn how to send our audio files to flask API using Postman for further processing.

Table Of Content:

  • Introduction
  • How To Send Audio Files To Flask API Using Postman?
  • Send wav file to flask API using postman
  • Send mp3 file to flask API using postman
  • Summary

Introduction:

In this post, I write some methods to send our audio files to Flask API from the postman. using this method we can send our audio files like wav or mp3 to Flask API and see the response of our Flask API.it is used to test our Flask API using postman before our API goes on the production server.it is good practice to try our API using postman.

How To Send Audio Files To Flask API Using Postman?

  • Send WAV file to Flask API using postman
  • Send MP3 file to Flask API using postman

Send WAV file to Flask API using postman

First, we have to create a Flask API. For this, we need to install Flask using pip.

pip install flask

Here is the python code for the create a Flask API. This code works for only WAV files.

Create a file app.py and add the below code into that file.

from flask import Flask,request

app=Flask(__name__)

@app.route("/",methods=["POST","GET"])
def main():
    try:
        if request.method=='POST':
         
            audio=request.files['audio']
            audio_name=audio.filename
            if '.wav' in audio_name:
            
                
                audio.save(audio_name)

                return {"response":"file saved successfully in your current durectory"}
            else:
                return {"error":"select you wave file"}
    except Exception as e:
        return {"error":str(e)}

if __name__=="__main__":
    app.run("0.0.0.0",debug=True)

Run the app.py file using the command:

python3 app.py

We get an URL http://localhost:5000/

Now open our postman and send a POST request as below.

Select POST request And then Body > form-data.

screenshot by the author

Now we have to select our wav files, click on the select files option and select our wav file.

screenshot by the author

Here we select a wav file now click on the SEND button.

screenshot by the author

Here, We can see the response of our Flask API which is written in our code.

Our WAV file is stored in the current directory where our app.py is located, we can find our file there. and use that file for further processing.

Continue…

Summary:

This is a simple way to send our audio files to Flask API using Postman.

You can also refer to this:

Happy Learning And Keep Learning…

Thank You…

References:

Leave a Comment