2

I'm trying to downsample a 16khz wav file to 8khz in python 2.6. The file has RIFF header and is in a mulaw format and must remain in that format.

I've glanced at some things in this big list of python stuff and can't seem to find a simple library that will just change the sample rate of an audio file.

Any suggestions on a good python library to do this?

1
  • 1
    Behind the scenes, any tool that does this will really convert from mulaw to pcm then doing the SR conversion, then convert to pcm back to mulaw. Thus when you say it must "remain" in mulaw format, you really mean it must be converted back to that format. (Forgive me for picking nits) May 31, 2013 at 22:02

2 Answers 2

1

I ended up installing sox and then calling it via subprocess:

from subprocess import Popen, PIPE, STDOUT
soxCall = '/usr/local/bin/sox ' + infileName + \
                 ' ' + outfileName + ' rate 8k'
p = Popen(soxCall, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT, close_fds=True)
0

audioop looks designed to suit your needs.

Supports mu-law and looks like it can adjust the sample rate with audioop.ratecv

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.