Created
October 31, 2012 16:27
-
-
Save jem-computer/3988063 to your computer and use it in GitHub Desktop.
Speech Synthesis in MacRuby
This file contains hidden or 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
framework 'AppKit' | |
module AppDelegate | |
extend self | |
def applicationDidFinishLaunching(notification) | |
voice_type = "com.apple.speech.synthesis.voice.GoodNews" | |
@voice = NSSpeechSynthesizer.alloc.initWithVoice(voice_type) | |
end | |
def say_hello(sender) | |
@voice.startSpeakingString("Hello World!") | |
puts "Hello World!" | |
end | |
def windowWillClose(notification) | |
puts "Bye!" | |
exit | |
end | |
end | |
# Inits NSApp | |
NSApplication.sharedApplication | |
NSApp.delegate = AppDelegate | |
# Allows an app without an applicaiton bundle or info.plist to still be an app | |
NSApp.setActivationPolicy NSApplicationActivationPolicyRegular | |
NSWindow.alloc.initWithContentRect( | |
[200,300,300,100], | |
styleMask:NSTitledWindowMask|NSClosableWindowMask, | |
backing: NSBackingStoreBuffered, | |
defer: false | |
).tap do |w| | |
w.title = "MacRuby: The Definitive Guide" | |
w.delegate = AppDelegate | |
w.contentView.addSubview( | |
NSButton.alloc.initWithFrame([80, 10, 120, 80]).tap do |b| | |
b.bezelStyle = 4 | |
b.title = 'Hello World!' | |
b.target = AppDelegate | |
b.action = 'say_hello:' | |
end | |
) | |
w.orderFrontRegardless | |
end | |
# Loads this app in front of the terminal (or whatever launched it) | |
NSApp.activateIgnoringOtherApps true | |
# Start the run loop | |
NSApp.run |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment