Re: [Bluemusic-users] python script and soundfile lengths
Brought to you by:
kunstmusik
From: peiman <pei...@gm...> - 2007-10-29 01:44:36
|
Hi Steven, I just found out what was wrong. I saved a copy of the file with peak and now it's working. In fact aifc module gives an error with the old file as well. I think I had previously saved my files with audacity so it must have something to do with that (although it was aif and readable by other programs). Anyways this is what I came up with in the end (it still needs a lot of work): import aifc import os import random score = "" count = 0 DIR = '/Applications/AudioSculpt 2.8.2/Sounds/segments' for f in os.listdir(DIR): if f.endswith('.aif'): count = count+1 soundfile = DIR+'/'+f p2 = random.random()* 5 p4 = random.random()+.5 file = aifc.open(str(soundfile), "r") sr = file.getframerate() frames = file.getnframes() length = float(frames)/float(sr)/p4 score += "i 1 " +str(p2)+' '+ str(length) +' '+ str(p4) + ' "'+ '\\Applications\\AudioSculpt 2.8.2\\Sounds\\segments\\' + str(f)+ '"'+ " \n" Steven Yi wrote: > > Hi Peiman, > > It *should* work. I can not say what is wrong but if you could send > me a copy of a file to use perhaps I can figure it out. (I see in > your other email that aiff module is working, but I am curious as to > why the result is so far off). > > Thanks! > steven > > On 10/28/07, peiman <pei...@gm...> wrote: >> >> Thanks Steven, >> >> This is great! SoundFileUtilities seems the easiest way to do it :-) The >> only thing is that I am getting a strange result. I have a file that is >> 12 >> seconds long SoundFileUtilities.getDurationInSeconds gives me >> 111.9157943726! Is it supposed to be in seconds? This is what I write: >> >> from blue.utility import SoundFileUtilities >> dur = >> SoundFileUtilities.getDurationInSeconds("/Users/peimankhosravi/Desktop/grainslonger.aif") >> >> score = "i 1 0 1" + str(dur) >> >> And I get: >> >> i1 0.0 111.9157943726 >> >> Thanks very much >> >> Best >> Peiman >> >> >> >> Steven Yi wrote: >> > >> > Hi Peiman, >> > >> > Because you are using the python object, you can use Java classes like >> > you would any other Python class. I have in blue a utility class >> > called SoundFileUtilities which has a method which can, given a string >> > filename, return the duration of the soundfile. This depends on the >> > soundFile being able to be read by JavaSound. To use it, use this >> > code: >> > >> > from blue.utility import SoundFileUtilities >> > dur = SoundFileUtilities.getDurationInSeconds("/path/to/file.wav") >> > >> > If you are using AIFF or AIFC files, python has a built-in module that >> > I saw is in the Jython distribution called aifc: >> > >> > http://docs.python.org/lib/module-aifc.html >> > >> > There is a wave module in my python 2.5 distribution but I do not see >> > one with Jython. You could try taking the wave.py file from a regular >> > python distribution and putting it in blue/lib/pythonLib or >> > ~/.blue/pythonLib to see if it will run with Jython. >> > >> > Hope that helps! >> > steven >> > >> > >> > On 10/28/07, peiman <pei...@gm...> wrote: >> >> >> >> Hello all, >> >> >> >> I was wondering if there is a way to pass the length of a sound-file >> to >> >> the >> >> python object (so that it is placed as p-field 3 (am I correct to >> think >> >> that >> >> macros won't work in blue?). I am making a script that reads samples >> from >> >> a >> >> directory and makes a note for each, but the note needs to be exactly >> the >> >> same length as, or shorter than the length of the samples, to avoid >> >> clicks >> >> (using an inbuilt envelope generator). >> >> >> >> Or maybe there is a python module that can get information about >> >> sound-files? >> >> >> >> Many Thanks >> >> Peiman >> >> -- >> >> View this message in context: >> >> >> http://www.nabble.com/python-script-and-soundfile-lengths-tf4706575.html#a13452353 >> >> Sent from the Csound - Blue - User mailing list archive at Nabble.com. >> >> >> >> >> >> >> ------------------------------------------------------------------------- >> >> This SF.net email is sponsored by: Splunk Inc. >> >> Still grepping through log files to find problems? Stop. >> >> Now Search log events and configuration files using AJAX and a >> browser. >> >> Download your FREE copy of Splunk now >> http://get.splunk.com/ >> >> _______________________________________________ >> >> Bluemusic-users mailing list >> >> Blu...@li... >> >> https://lists.sourceforge.net/lists/listinfo/bluemusic-users >> >> >> > >> > >> ------------------------------------------------------------------------- >> > This SF.net email is sponsored by: Splunk Inc. >> > Still grepping through log files to find problems? Stop. >> > Now Search log events and configuration files using AJAX and a browser. >> > Download your FREE copy of Splunk now >> http://get.splunk.com/ >> > _______________________________________________ >> > Bluemusic-users mailing list >> > Blu...@li... >> > https://lists.sourceforge.net/lists/listinfo/bluemusic-users >> > >> > >> >> -- >> View this message in context: >> http://www.nabble.com/python-script-and-soundfile-lengths-tf4706575.html#a13458501 >> Sent from the Csound - Blue - User mailing list archive at Nabble.com. >> >> >> ------------------------------------------------------------------------- >> This SF.net email is sponsored by: Splunk Inc. >> Still grepping through log files to find problems? Stop. >> Now Search log events and configuration files using AJAX and a browser. >> Download your FREE copy of Splunk now >> http://get.splunk.com/ >> _______________________________________________ >> Bluemusic-users mailing list >> Blu...@li... >> https://lists.sourceforge.net/lists/listinfo/bluemusic-users >> > > ------------------------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. > Still grepping through log files to find problems? Stop. > Now Search log events and configuration files using AJAX and a browser. > Download your FREE copy of Splunk now >> http://get.splunk.com/ > _______________________________________________ > Bluemusic-users mailing list > Blu...@li... > https://lists.sourceforge.net/lists/listinfo/bluemusic-users > > -- View this message in context: http://www.nabble.com/python-script-and-soundfile-lengths-tf4706575.html#a13460362 Sent from the Csound - Blue - User mailing list archive at Nabble.com. |