Skip to content

Instantly share code, notes, and snippets.

@eliasdorneles
Last active May 14, 2020 01:55
Show Gist options
  • Save eliasdorneles/afc0048239f81e7c29d8 to your computer and use it in GitHub Desktop.
Save eliasdorneles/afc0048239f81e7c29d8 to your computer and use it in GitHub Desktop.
Playing notes with sox
import subprocess
import time
def wait(seconds):
time.sleep(seconds)
def play_note(note='C', duration=4, delay=0):
# requires sox to be installed
command = (
"play -qn synth {duration} pluck {note}"
" fade l 0 {duration} 2 reverb"
).format(note=note, duration=duration)
subprocess.Popen(command.split())
if delay:
wait(delay)
play_note('C', delay=0.1)
play_note('E', delay=0.1)
play_note('G')
wait(0.5)
play_note('C', delay=0.1)
play_note('F', delay=0.1)
play_note('A')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment