Skip to content

Instantly share code, notes, and snippets.

@mikz
Created December 14, 2010 11:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikz/740300 to your computer and use it in GitHub Desktop.
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.
#/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