Skip to content

Instantly share code, notes, and snippets.

@gpirrotta
Last active October 16, 2022 05:40
Show Gist options
  • Save gpirrotta/78aaac02bdefb2c9347bb7c344d4b8e3 to your computer and use it in GitHub Desktop.
Save gpirrotta/78aaac02bdefb2c9347bb7c344d4b8e3 to your computer and use it in GitHub Desktop.
OpenDataZen, data sonification del CAD
import pandas as pd
from pydub import AudioSegment
rain = AudioSegment.from_file("../sounds/rain_background.wav", format="wav")
wind = AudioSegment.from_file("../sounds/wind.mp3", format="mp3")
thunder = AudioSegment.from_file("../sounds/thunder.wav", format="wav")
bird = AudioSegment.from_file("../sounds/bird.mp3", format="mp3")
df=pd.read_csv('../data/gitdiff.csv')
current_time=0
for item in df.to_dict('records'):
current_time+=int(item['size_article']/10)
if item['type']=='updated':
print(f"Updated {current_time}")
rain = rain.overlay(wind, position=current_time, gain_during_overlay=-2)
elif item['type']=='new':
print(f"New {current_time}")
rain = rain.overlay(bird, position=current_time, gain_during_overlay=-2)
elif item['type']=='deleted':
current_time+=5000 # add 5 seconds because deleted event has 0 secs in csv file
print(f"Deleted {current_time}")
rain = rain.overlay(thunder, position=current_time, gain_during_overlay=-2)
rain = rain[:current_time]
rain.export("../sounds/opendatazen.mp3", format="mp3")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment