Datascience sonification.

12 views
Skip to first unread message

Gabriele Battaglia

unread,
Mar 2, 2024, 2:23:39 PM3/2/24
to pyo-d...@googlegroups.com
Hi everyone,
I would like to learn a tool that allows me to sonify a series of
numerical data. I'm afraid I don't have the skills to create one myself,
even though I've tried and gotten some results. However, I would like to
avoid reinventing the wheel and use a project that is definitely better
than what I could do.
I had found astronify on github, based on pyo, which seems to be a dead
project, not developed for years, and unfortunately gives me an error
when importing, so I can't use it.
Well, I'm writing to you in the hope that you have read something about
this that you can direct me to. I understand that I am at the edge of
the topic of this list, but... I'll give it a try and cross my fingers.

Thank you in any case and best regards.

--

Gabriele Battaglia (IZ4APU)
--... ...-- -.. . .. --.. ....- .- .--. ..- - ..- . .
Sent from my Giant Desktop PC

Bibiko

unread,
Mar 4, 2024, 6:39:18 AM3/4/24
to pyo-discuss
Hi Gabriele,
oh my goodness, sonification is a really, really broad field. It depends on what you want to hear based on the data available.

If you have Pyo installed on your computer (it can be a little tricky sometimes), you might want to take a look at the following Python script as a trivial and naive starting point, which only works with Pyo. You can "play around" with all the parameters a lot. If you have wxPython installed, you can also do this live, as Pyo comes with two methods: {var_name}.ctrl() and {var_name}.graph(). Read the documentation, but if you don't know Pyo at all, it takes a little time to understand Pyo, but it's worth it :)
-----------------------
from pyo import *
from pyo.lib._wxwidgets import (tFromValue, interpFloat)
import random


s = Server(duplex=1).boot().start()

# any data as a list of floats
data = [random.uniform(1, 5) for x in range(1000)]

# set the lowest and highest output frequency in Hertz
low_freq = 200
high_freq = 800

# set duration and spacing of a note (frequency) in sec
note_duration = .02
note_spacing = .001

# normalize data into a range of 0...1
norm_data = [tFromValue(a, min(data), max(data)) for a in data]

# transform/interpolate normalized data between low_freq and high_freq
freq_data = [interpFloat(a, low_freq, high_freq) for a in norm_data]

# load a pyo table with these frequencies
tab = DataTable(size=len(freq_data), init=freq_data)

# start a clock generator - how quickly the frequencies are played in succession
m = Metro(note_duration+note_spacing).play()

# create a counter to iterate through the data table
c = Counter(m, min=0, max=len(freq_data), dir=0)

# get the frequency from freq_data according to counter
pit = TableIndex(tab, c)

# create an envelope around each played note (frequency) in sync with the clock generator
env = Expseg([
                (0, 0),
                (note_duration/8, 1),
                (note_duration, 0),
                ((note_duration+note_spacing), 0)
            ],
            exp=1., loop=True, mul=.1).play()

# play the current note as a sinus wave in succession
a = Sine(freq=pit, mul=env).mix(2).out()

# if you like add a bit reverb - if so, you can remove '.out()' from Sine(...)
d = WGVerb(a, feedback=[.8, .95], cutoff=high_freq*3, bal=.5, mul=1.).out()

# if you have wxPython installed:
s.gui(locals())

# if you haven't install wxPython:
try:
    while True:
        input('Press ENTER to quit')
        break
except Exception:
    pass
--------------------

Best, Hans

gabriele....@gmail.com

unread,
Mar 4, 2024, 7:46:51 AM3/4/24
to pyo-d...@googlegroups.com

Ciao Hans.

Many, many thanks for this fine answer.

Yes I have the basics of Pyo.

I like your script very much and I’ll go to play with it. My idea is to be able to have a parametrized sound. I would like to give the time ax to the stereo field: 0 at the very left and last data at the very right, then pitch linked to the values on y axis.

Astronify allows to to work with pandas and you could pass to it 1 or more columns of your DataFrame. But as far as I know it works in mono by the way and above all it’s an abandoware project.

 

Anyway, again all mygratitude, I’m going to save and study your script.

Gabe.

Reply all
Reply to author
Forward
0 new messages