Dear all,

I recently wrote a script (attached at the end of this email) that, for each .wav file in the folder/directory where the script is run:
  1. smoothly pans the audio from left to right over its full duration for spatial effect (such that x is mapped both to time and space).
  2. exports the file as a .ogg file, saving memory (without noticeable loss in quality).

In order to make use of the script, you will have to save sonifications as .wav files after generating them. Run `my_sonification.write(file_name.wav)` after running `my_sonification.sonify()` to save the sonification as a .wav file that can be played at a later time, shared with others, etc. Replace 'my_sonification' with the relevant variable and 'file_name' with whatever name you choose. Note that Web browsers and audio players should be able to handle the .wav file on your system.

The script also has two additional dependencies before it can be used:
  1. FFmpeg (Use `conda install ffmpeg`)
  2. PyDub (Use `pip install pydub`)

Once you've installed the dependencies, navigate to the folder that contains your .wav files (using `cd path_to_folder`), start your IPython session by typing `ipython`, and run the script using `%run pan_and_compress.py`.

If the script runs successfully, then all of the .wav files in the folder should have been converted to .ogg files that have spatial audio (panned across the left and right channels) and that are much smaller in size than the original .wav files.

You can then open the .ogg files in a Web browser or audio player to hear the audio. Using headphones can make the sonification sound more immersive as the sound moves from left to right as it plays. Based on the perceived location of the sound at any given point, you can estimate your position in the sonification (e.g., you hear a peak halfway through the audio (in the center) or about a third of the way into it (to the left)).

If you would like to play your new .ogg file in the IPython command line directly (to avoid the need for other programs), use the following steps:
  1. Run `import subprocess`
  2. Run `subprocess.run(['ffplay', '-autoexit', 'file_name.ogg'])`
Note that you can hit the Escape key on the top left of your keyboard to stop playback at any time while the sonification is playing from your terminal using the above steps. Consider using headphones however/wherever you choose to play the file.

You will find 1) the script 'pan_and_compress.py' and 2) 'sample_spatial_sonification.ogg' attached to this email. You can listen to the sample spatial sonification to get an idea of the left-right panning. Remember to move the script into the folder where you would like to use it.

Please let me know if you try it out and/or if you have any questions.

Best,
Nikhil

P.S.: The sample sonification is of the mathematical function the cosine of x squared, y = cos(x**2), from x = -6 to x = 6. Python uses two stars to indicate exponentiation.