python-3.xwavscapyconvertersamr

Convert RTP Payload (payload type 107, AMR-WB 16khz 1Channel) to .wav


I'm working in Python 3.6 under Linux Ubuntu and I used the Scapy lib to extract data from a bin file which contained the following stack: IP/UDP/RTP. The RTP-PAYLOAD TYPE is 107 (dynamic), a=rtpmap:107 AMR-WB/16000/1.

I put it into a file in raw format and I called it src.aud, but it also wouldn't be a problem to put write it in hex. Now what do I have to do exactly to transform it into audio data format like .wav or .mp3 for example, which is on every computer?

I've already made an' effort with this file:

https://gist.github.com/ollyja/5fe34ba997d8fa8a3f6ff4fb883feca2

But there is a dependency on SILK audio decoder.

https://github.com/gaozehua/SILKCodec

But that's all written in C and I don't understand how to use it in my environment. Isn't there a simplier way or do I miss s.th. ?

Thanks for Your help


Solution

  • Document RFC4867 (can easily found with google), chapters 4.3, 4.4 and 5. First it must be found out, if the RTP-PAYLOAD is bandwidth efficient (chapter 4.3) or octet aligned (4.4). In this case it's bandwidth efficient according 4.3.4. and it must be transformed according chapter 5, 5.1 and 5.3 before writing it into a file.amr or file.awb (both works).

    The resulting file can be listened to with VLC-Media player and with 'Videos' of Linux Ubuntu. But it can also be converted into all kinds of audiofiles by the online-converter 'convertio'.

    https://convertio.co/it/
    

    A direct way to do that in Python is the Python library ffmpy that has FFmpeg wrapped.

    https://ffmpy.readthedocs.io/en/latest/
    

    Under Quickstart there is an' example that resolves the problem.