Search code examples
python3gp

How to receive 3gp file from android and decode it using python?


I'm trying to receive a 3gp file from android and use the values in to inference a machine learning model in my server. The server codes are in python.

When I open the file I received using the code below,

AudioSegment.from_file(BytesIO(posted_data), format="3gp")

The outputs are values that are too big for a normal audio. I think this is because the android encoded the values with MediaRecorder's AMR_NB codec, but was not decoded properly in server. Is there anyway I can properly decode the bytes I received in python server?


Solution

  • FFmpeg is widely recognized as a Swiss army knife of audio/video conversion. It has Python bindings. I don't know the quality of those bindings, but if the conversion is meant as a one-off thing, you could also consider using the very mature FFmpeg program to convert your file to uncompressed audio (like WAV) before processing it with your code. Even the Python standard library can deal with WAV.