Created
December 14, 2010 11:37
-
-
Save mikz/740300 to your computer and use it in GitHub Desktop.
Randomly selects body parts and colors and then speaks instructions. Controller by voice. Depends on MacRuby.
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
#/usr/bin/env ruby | |
framework "AppKit" | |
app = NSApplication.sharedApplication | |
class TwisterDelegate | |
SIDES = %w{left right} | |
BODY_PARTS = %w{foot hand} | |
COLORS = %w{red green blue yellow} | |
def init | |
voices = NSSpeechSynthesizer.availableVoices | |
@synthesizer = NSSpeechSynthesizer.alloc.initWithVoice nil | |
if super | |
self | |
end | |
end | |
def speechRecognizer(sender, didRecognizeCommand:command) | |
spinned = spin | |
sleep 1 | |
text = "move #{spinned[0]} #{spinned[1]} to #{spinned[2]}" | |
puts text | |
@synthesizer.startSpeakingString text | |
end | |
def spin | |
[SIDES, BODY_PARTS, COLORS].collect{ |array| | |
array[rand(array.length)] | |
} | |
end | |
end | |
recognizer = NSSpeechRecognizer.new | |
#recognizer.displayedCommandsTitle = "Twister" | |
recognizer.listensInForegroundOnly = false | |
recognizer.blocksOtherRecognizers = true | |
recognizer.commands = %w{next twist time computer finder chicken fake dog sex black new} | |
recognizer.delegate = TwisterDelegate.alloc.init | |
recognizer.startListening | |
#NSRunLoop.currentRunLoop.runUntilDate(NSDate.distantFuture) | |
app.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment