Cropping sound files

Dieter Vanderelst dieter.vanderelst at gmail.com
Wed Nov 30 09:54:40 EST 2005


Hello,

My previous problem with Winsound has boiled down to a new problem.

I have some soundfiles (wav) of which I only need the n first seconds. 
So, I thought I could crop them using
the standard wave-module:

This is some of my code:
   
    #I open the wav file and I read the first n frames
    f_org = wave.open(file_name, 'r')
    frames =  f_org.readframes(f_org.getframerate( )*sec)

    #these frames I write to a new file
    #the parameters for the new file are the same as for the original file,
    #only the number of frames is different
    f_new.setparams(pra)
    f_new.writeframesraw(frames).

This works fine for short files (up to 20 sec). But if I try this with 
larger files, an later play the new cropped files with windsound, 
winsound doesn't play the whole
new file (although windows media player does so).

Does anybody has a piece of code that I can use to crop my files? 
Because I must be doing something wrong.

Thanks,
Dieter


Graham Fawcett wrote:

>Dieter Vanderelst wrote:
>  
>
>>Hello,
>>
>>I'm having a problem with playing WAV files using Winsound.
>>
>>If I use winsound to play a certain WAV files only the first few seconds
>>of the file get played. I think this comes because these files contain
>>some parts of silence. There winsound seems the stop playing the files
>>(windows media player plays the sounds correctly).
>>    
>>
>[snip]
>  
>
>>Just as a reference, the code I use:
>>winsound.PlaySound("My_wav.wav", winsound.SND_FILENAME)
>>    
>>
>
>This is totally a guess, but add the following to the end of your test
>script:
>
>import time
>time.sleep(10)
>
>Did the file play for ten seconds longer? I don't know anything about
>winsound, but I'm guessing that the PlaySound call is non-blocking, and
>your playback stops because your process is quitting before the sound
>has played.
>
>Graham
>
>  
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20051130/7cd96b39/attachment.html>


More information about the Python-list mailing list