Write .3gp file into .wav format python Flask server

1.1k Views Asked by At

I need to record a .3gp audio file coming from the Android front-end to be converted into .wav audio using the python Flask server back-end for further processing. Any suggested method or library to convert .3gp audio into .wav audio format?

audiofile = flask.request.files['file']
filename = werkzeug.utils.secure_filename(audiofile.filename)    
audiofile.save('Audio/' + filename)

I'm using this code now which receives the audio file as .3gp. I need to convert this into .wav format

1

There are 1 best solutions below

1
On BEST ANSWER

Update: You can also do it using ffmpeg
Method 1:
https://github.com/adaptlearning/adapt_authoring/wiki/Installing-FFmpeg#installing-ffmpeg-in-ubuntu
bash
ffmpeg -i path/to/3gp.3gp path/to/wav.wav
or
python (which runs bash command)

import os
os.system('ffmpeg -i path/to/3gp.3gp path/to/wav.wav')

Method 2:
Convert .3gp to .mp3 then .mp3 to .wav
Use https://pypi.org/project/ftransc/ to convert .3gp to .mp3. Currently there is no python API for that so either use

  1. bash
    ftransc -f mp3 filename.3gp give the destination - check for help
    OR
  2. python
os.system('ftransc -f mp3 filename.3gp')

Then use pydub https://github.com/jiaaro/pydub#installation to convert .mp3 to .wav

newAudio = AudioSegment.from_mp3('path/to/mp3')
newAudio.export('path/to/destination.wav', format="wav")