Skip to content

Instantly share code, notes, and snippets.

@jamesdabbs
Last active November 13, 2016 00:01
Show Gist options
  • Save jamesdabbs/a85fa5553df7dba0ba3dbb25f4cafe4b to your computer and use it in GitHub Desktop.
Save jamesdabbs/a85fa5553df7dba0ba3dbb25f4cafe4b to your computer and use it in GitHub Desktop.
In response to @celeenr's (https://twitter.com/celeenr) RubyConf 2016 talk "Rhythmic Recursion"
class Voice
BASELINE = %w( there is no - poop ing - on - the bus - )
VOICES = `say -v '?'`.lines.map { |line| line.split.first }
def initialize &voice
@voice, @i = voice, -1
end
def perform
advance
Thread.new do
@voice.(BASELINE[@i], @i) unless BASELINE[@i] == "-"
end
end
def advance
@i = (@i + 1) % BASELINE.length
end
end
a = Voice.new do |word,_|
system "say -r 250 -v Alice #{word}"
end
b = Voice.new do |word,_|
vol = word == "there" ? 1 : 0.5
system "afplay -v #{vol} /System/Library/Sounds/Tink.aiff"
end
13.times do
(Voice::BASELINE.length * 4).times do
a.perform
b.perform
sleep 0.15
end
a.advance
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment