Hi guys,
I have a program that lets the user play a sound but i was wanting to know how i could make it so the user could vary the speed in which the sound plays so the sound can play slowly and quickly and normaly as well. Is this even possible with python? Becuase i was looking and i couldn't find any modules to help me with this problem but if anyone could give me a hand that would be greatly appreciated.
Thanks.

Recommended Answers

All 23 Replies

What platform are you on? What module are you using for playback right now?

I don't know about python but the trick of doing this is increasing the tempo of music. If the current module you are using can do that then that will be simple case

Similiar to what evstevemd said, I was thinking you would need to change the sample rate (how many bits per second are played) if you take a 44000hz sample and play it at 88000hz, it should play at double speed.

Well im on windows if that helps. How would i change the sample rate? Is there an easy way to do that in python?

Okay well got an update for everyone. I am using pyAudio and wave modules to play my .wav file. Now i can set the "Rate" in which the file plays. This i can change at the start of the program and it will change the rate at which the sound is played. This changes the speed and therefore the pitch. My issue is, with using pyAudio i haven't been able to work out how to change the rate while the application is running.

So if anyone knows how to do that. That will be very helpful.

site for pyaudio that i can download and fiddle around? Is it built in? wx.Python??

I think a better option might be to switch to pySonic

http://pysonic.sourceforge.net

the Song.userspeed() property in particular looks like what you would want

Is there anywhere to download pysonic for python 2.5? Because i cant find it on the sourceforge page..

Is there anywhere to download pysonic for python 2.5? Because i cant find it on the sourceforge page..

Find file pysonic.pyd installed on Python24 and copy it to Python25
pysonic will work with python25 if you hexedit pysonic.pyd
--> find the python24.dll ref. and change it to python25.dll
you can use for instance the ICY hexplorer utility

There may be a runtime version warning, but it works otherwise.

Is there anywhere to download pysonic for python 2.5? Because i cant find it on the sourceforge page..

Find file pysonic.pyd installed on Python24 and copy it to Python25
pysonic will work with python25 if you hexedit pysonic.pyd
--> find the python24.dll ref. and change it to python25.dll
you can use for instance the ICY hexplorer utility

There may be a runtime version warning, but it works otherwise.

Is there anywhere to download pysonic for python 2.5? Because i cant find it on the sourceforge page..

Find file pysonic.pyd installed on Python24 and copy it to Python25
pysonic will work with python25 if you hexedit pysonic.pyd
--> find the python24.dll ref. and change it to python25.dll
you can use for instance the ICY hexplorer utility

There may be a runtime version warning, but it works otherwise.

So i have to install python 2.4 on my computer still to do that?

seems as if project is dead, just like Boa

Ah bummer. Should i move this project onto another language such as C++ or do you rekon i could still do it in python?

Ah bummer. Should i move this project onto another language such as C++ or do you rekon i could still do it in python?

Simply go to the C++ forum here and ask. There are plenty of experts there that know how to handle sound files.

Sorry about putting my quatsch up three times, but DaniWeb kept on freezing up when I did it.

what if you dig one module and fiddle with codes to come out with YOUR results?

The sound module I dig is pymedia, here is an example:

#! /bin/env python
# PyMedia wave play
# download: pymedia-1.3.5.0-pre2.win32-py2.4.exe
# free from: http://pymedia.org/
# pymedia will work with python25 if you hexedit all 5 .pyd files
# in the pymedia installed folder and its subfolders
# --> find python24.dll and change to python25.dll

import sys

def playWAV( fname ):
    import pymedia.audio.sound as sound
    import time, wave
    f = wave.open( fname, 'rb' )
    # speed things up by multiplying the samplerate, also gives higher frequency
    #sampleRate = f.getframerate()*2
    sampleRate = f.getframerate()
    channels = f.getnchannels()
    format = sound.AFMT_S16_LE
    print sampleRate, channels, format  # test => 8000 1 16
    snd1 = sound.Output( sampleRate, channels, format )
    #s = f.readframes( 300000 )
    #snd1.play( s )

    s = ' '
    while len(s):
        s = f.readframes( 1000 )
        snd1.play( s )

  
    # since sound module is not synchronous we want everything to be played before we exit
    while snd1.isPlaying(): time.sleep( 0.05 )


if __name__== '__main__':
    """
    if len( sys.argv )!= 2:
        print "Usage: play_wav <file>"
    else:
        playWAV( sys.argv[ 1 ] )
    """
    # pick a wave you have
    waveFile = 'boing.wav'
    playWAV(waveFile)

Again, all further development seems to have stopped in 2006. Makes you wonder how much longer Python will last?

Okay, so python 2.4 for that one as well. cool, ill download it to test it out.

Gosh yeah, how much longer heh? If developers arent making things for it any more it is going to quickly fall behind and gradually die i guess. I hope not!

Gosh yeah, how much longer heh? If developers arent making things for it any more it is going to quickly fall behind and gradually die i guess. I hope not!

That will be very sad!:(

What is the chance of that happening do you rekon?

Thanks a lot for that!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.