Play Sounds at different Speeds
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.
Paul Thompson
Veteran Poster
1,119 posts since May 2008
Reputation Points: 264
Solved Threads: 183
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
evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
Well im on windows if that helps. How would i change the sample rate? Is there an easy way to do that in python?
Paul Thompson
Veteran Poster
1,119 posts since May 2008
Reputation Points: 264
Solved Threads: 183
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.
Paul Thompson
Veteran Poster
1,119 posts since May 2008
Reputation Points: 264
Solved Threads: 183
site for pyaudio that i can download and fiddle around? Is it built in? wx.Python??
evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
Is there anywhere to download pysonic for python 2.5? Because i cant find it on the sourceforge page..
Paul Thompson
Veteran Poster
1,119 posts since May 2008
Reputation Points: 264
Solved Threads: 183
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.
sneekula
Nearly a Posting Maven
2,427 posts since Oct 2006
Reputation Points: 961
Solved Threads: 212
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.
sneekula
Nearly a Posting Maven
2,427 posts since Oct 2006
Reputation Points: 961
Solved Threads: 212
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.
sneekula
Nearly a Posting Maven
2,427 posts since Oct 2006
Reputation Points: 961
Solved Threads: 212
So i have to install python 2.4 on my computer still to do that?
Paul Thompson
Veteran Poster
1,119 posts since May 2008
Reputation Points: 264
Solved Threads: 183
seems as if project is dead, just like Boa
evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
Ah bummer. Should i move this project onto another language such as C++ or do you rekon i could still do it in python?
Paul Thompson
Veteran Poster
1,119 posts since May 2008
Reputation Points: 264
Solved Threads: 183
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.
sneekula
Nearly a Posting Maven
2,427 posts since Oct 2006
Reputation Points: 961
Solved Threads: 212
what if you dig one module and fiddle with codes to come out with YOUR results?
evstevemd
Senior Poster
3,713 posts since Jun 2007
Reputation Points: 462
Solved Threads: 392
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?
sneekula
Nearly a Posting Maven
2,427 posts since Oct 2006
Reputation Points: 961
Solved Threads: 212
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!
Paul Thompson
Veteran Poster
1,119 posts since May 2008
Reputation Points: 264
Solved Threads: 183