speed up mp3

Dmitry Borisov jbors at mail.ru
Tue Oct 26 22:40:34 CEST 2004

From: "Ivo Woltring" <TheDolphin at ivonet.nl>
To: python-list at python.org
Date: Tue, 26 Oct 2004 21:16:31 +0200
Subject: speed up mp3

> Dear Pythoneers,
> I have a blind friend who listens a lot to audio books. A lot of the
> material available today is in mp3 format.
> For ages i have been looking for a mp3-player with speed control and haven't
> found any.
> Next option: write one yourself.
> And I have ;-). with the PyMedia module.
> It is an only sleightly adjusted version of one of the examples.
> Now the Question:
> Is it possible to re-Encode mp3 files with this faster speed as to make them
> portable to e.g. Pocket PC (without python interpreter) or standard MP3
> player (hardware)?
> The files have to play at about 1.5 times the normal speed.
> I tried it with PyMedia but I only get errors. Any help would be
> appreciated.

You cannot directly play sound at the sample rate you want. Soundcards supports only fixed sample rates.
Here is the example that works with resampler:
( from aplayer.py )
      print 'Opening sound with %d channels -> %s' % ( r.channels, snds[ card ][ 'name' ] )
      snd= sound.Output( r.sample_rate, r.channels, sound.AFMT_S16_LE, card )
      resampler= sound.Resampler( (r.sample_rate,r.channels), (r.sample_rate/1.5,r.channels) )
    if r:
      data= resampler.resample( r.data )
      snd.play( data )

Unfortunately there is a bug in current resample() which makes holes in the sound. I have fixed that and it will be in release next week.

More information about the Python-list mailing list