Last active
May 14, 2020 01:55
-
-
Save eliasdorneles/afc0048239f81e7c29d8 to your computer and use it in GitHub Desktop.
Playing notes with sox
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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