Skip to content

Instantly share code, notes, and snippets.

@connordavenport
Created April 9, 2020 13:19
Show Gist options
  • Save connordavenport/9752b494ac5c2076de1fec6ef465c87f to your computer and use it in GitHub Desktop.
Save connordavenport/9752b494ac5c2076de1fec6ef465c87f to your computer and use it in GitHub Desktop.
plot a .wav in drawbot
from scipy.io import wavfile
fs, data = wavfile.read("Untitled2.wav")
# for this case I only needed the left waveform
left = [a[0] for a in data.tolist()]
seconds = data.shape[0]/fs
fps = fs
duration = 1 / fps
totalFrames = round(seconds * fps)
# I was too lazy to scale anything so I made a massive image file:)
w, h = totalFrames+200, max(left)+abs(min(left))+100
newPage(w, h)
fill(1, 0, 0)
# translate to the center of the page
translate(100, h / 2)
a = 1
for p,r in enumerate(left):
rect(1*p,0,3,r)
a += 1
saveImage("./myWaveforms.pdf")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment