I am debugging a bit of code that processes an RTP voice stream in uLaw or aLaw format. I want to capture the samples that pass through my code and store them into a file. That is easy enough. My question is: is there a file format in which I could easily encapsulate that raw data so it could be played by some common player software?
I know the sample rate, it's 8000 per second -- telephony default.
I could transform every sample in its 16-bit PCM equivalent and make a WAV file, but I'd really like to avoid having to do that.
If you have SoX, you can write your encoded data to a binary file, and play it back using a bunch of command line options to tell SoX the correct format. I think you can do:
$ sox --bits 8 --channels 1 --encoding mu-law --rate 8000 file.raw --default-device
It always takes me a couple of tries to get the options right, but it's a useful utility for dealing with audio data. The command line should be the same across OSes. If the --default-device
option doesn't correctly work for you, you can specify an output WAV (or whatever) file instead.
Note the extension of the file is important. SoX will use the extension to try and predict some of the channel/bitwdith/sample rate parameters. sox -h
will show you the full list of recognized file types.