see: http://pymedia.org

Needs additional libraries for mp3 encoding and ogg decoding/encoding, otherwise it's easy to use. Here is a sample implementation of a recoder (will throw exceptions on corrupted files):

#!/usr/bin/env python

import pymedia.audio.acodec as acodec
import pymedia.muxer as muxer
from cStringIO import StringIO

def recode_mp3(ins, br=None, sr=None):
	dm = muxer.Demuxer('mp3')
	frames = dm.parse(ins)
	if not frames:
		raise 'ooooooooooooooooooooooooooo'

	dec = acodec.Decoder(dm.streams[frames[0][0]])

	outs = StringIO()
	r = dec.decode(frames[0][1])
	params = {
		'id': acodec.getCodecID('mp3'),
		'bitrate': br or r.bitrate,
		'sample_rate': sr or r.sample_rate,
		'channels': r.channels
	}
	enc = acodec.Encoder(params)
	mx = muxer.Muxer('mp3')
	s_id = mx.addStream(muxer.CODEC_TYPE_AUDIO, params)
	outs.write(mx.start())

	for fr in frames:
		for efr in enc.encode(dec.decode(fr[1]).data):
			outs.write(mx.write(s_id, efr))
	return outs.getvalue()

import sys
open(sys.argv[2], 'wb').write(recode_mp3(open(sys.argv[1], 'rb').read()))

This script expects an input and output filename as parameters and does not change the bitrate. The 'br' and 'sr' parameters for the function are bitrate and samplerate, respectively.

Otherwise, it would be better to do the recoding in a new process (with lame) so the priority can be reduced. Also, recodings should be queued to prevent DoS attacks.