Package: pyAudGrav
pyAudGravpyAudGrav is a compositional tool, implemented in python, that allows a user to algorithmically edit and rearrange audio clips, both in time and space, using gravity. Gravity, in this case, is metaphor used to describe the relationship between sound objects.Note: This is a subtle shift example that is meant to illustrate the direction that audio events move in relationship to other events.After the audio file is read, the program will edit out each audio event and treat it as an independent sound object. AnAudioEvent()in this case, is defined as a section of audio that is preceded and followed by the noise floor of the original sound file. To approximate the behavior of gravity for these audio events we use Newton's universal law of gravity. The law describes that the force due to gravity is equal to the product between two masses divided by their distance squared and multiplied by a gravitational constant.Audio events, based on their mass and distance from other events, will excerpt an attractive force on other audio events. For our purposes, mass is equated as the RMS value of each event and the distance is the time, in seconds squared, in between each events peak index. When actually calculating gravity, we would multiply the equation by the gravitational constant, 9.81 meters per seconds squared, but since audio has no gravitational constant this parameter is exposed to the user to affect the magnitude of shifting. The end result is a new audio file with events that have shifted in time and space (stereo panning) based on mass and distances.InstallationTo install use...pip install pyAudGravorpip install git+https://github.com/patrickTumulty/pyAudGravGetting StartedThe package install comes with several example audio files that can be quickly loaded via the following functions. NOTE:pyAudGravcurrently only supports the importing of MONO files. After the initial analysis the new file can be exported to MONO or STEREO.load_example1()# example1_stimmen.wavload_example2()# example2_tones.wavload_example3()# example3_potsPans.wavload_example4()# example4_pingPong.wavload_example5()# example5_hey.wavThese files can also be downloaded directly from the github repository [/DOCUMENTATION/IncludedExamples]. To use one of these examples you can use the
following code.importpyAudGravimportmatplotlib.pyplotaspltio=pyAudGrav.load_example1()# pre packaged audio exampleanalyzer=pyAudGrav.AudioAnalysis(io.data,io.sample_rate)# create an analyzer objectenv=analyzer.get_end_peak(analyzer.data)# generate envelopeanalyzer.calc_shift(analyzer.data,env,gConst=4)# calculate gravity shiftingrStruct=pyAudGrav.AudioReconstruct(len(analyzer.data),analyzer.audio_events)# create reconstruction objectnew_signal=rStruct.reconstruct_stereo()# reconstruct stereo signalio.writeWav("Example1_before.wav)                   # originalio.writeWav("Example1_after.wav",new_signal)# new audio file# == Plot New Signal ==plt.title("Reconstructed Signal Over Original Signal")plt.xlabel("Time (samples)")plt.ylabel("Amplitude")plt.plot([i+rStruct.correctionforiinrange(len(analyzer.data))],[itemforiteminanalyzer.data],'grey')plt.plot(new_signal,'r')plt.plot([obj.peakIdx+obj.offset+rStruct.correctionforobjinanalyzer.audio_events],[obj.panOffset*0.01forobjinanalyzer.audio_events],'.b')plt.show()To use your own audio file simply swap...io = pyAudGrav.load_example1()withio = pyAudGrav.AudioIO("/filePath")pyAudGrav has a built in function calledloop_gravity()that allows the user to iterate over the same data set multiple times. This approach yields interesting and different results to that of the example above. The syntax for achieving this is similar to the previous example with a couple differences. In this exampleloop_gravity()is used in place ofcalc_shift(). In additionloop_gravity()will return the final iteration of the looped data. This means that there is no need to create a reconstruction object as is seen in the previous example. Note thatloop_gravity()will deconstruct and reconstruct the data as a mono data array until the final iteration where it will become stereo.importpyAudGravimportmatplotlib.pyplotaspltio=pyAudGrav.load_example1()analyzer=pyAudGrav.AudioAnalysis(io.data,io.sample_rate)env=analyzer.get_env_peak(analyzer.data)new_signal=analyzer.loop_gravity(analyzer.data,env,numLoops=4,gConst=4,plot=False)io.writeWav("Example1_after.wav",r)plt.plot([i+analyzer.rStruct.correctionforiinrange(len(analyzer.data))],[itemforiteminanalyzer.data],'grey')plt.plot(new_signal,'red')plt.plot([item.peakIdx+item.offset+analyzer.rStruct.correctionforiteminanalyzer.audio_events],[item.panOffset*0.01foriteminanalyzer.audio_events],'.blue')plt.show()The code above illustrates the minimum code required to create a new audio file. Examination of thecalc_shift()andloop_gravity()functions will reveal some of the other parameters available to fine tune the pyAudGrav algorithm. For best results the user is encouraged to experiment with these parameters.For a more in depth overview and explanation of pyAudGrav and its classes, please refer to the DOCUMENTATION folder above.