Skip to content

Instantly share code, notes, and snippets.

@yhirose
Created July 29, 2012 03:30
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 yhirose/3195925 to your computer and use it in GitHub Desktop.
Save yhirose/3195925 to your computer and use it in GitHub Desktop.
MacRuby
#------------------------------------------------------------------------------
# play_sound
#------------------------------------------------------------------------------
def play_sound(url_string)
url = NSURL.URLWithString(url_string)
s = NSSound.alloc.initWithContentsOfURL(url, byReference: false)
s.delegate = self
s.play
end
def sound(sound, didFinishPlaying: state)
end
#------------------------------------------------------------------------------
# alertOk
#------------------------------------------------------------------------------
def alertOk(caption, message)
NSAlert.alertWithMessageText(caption,
defaultButton: "OK",
alternateButton: nil,
otherButton: nil,
informativeTextWithFormat: message).runModal
end
#------------------------------------------------------------------------------
# say
#------------------------------------------------------------------------------
def say(text)
NSSpeechSynthesizer.availableVoices().each do |voice_type|
voice = NSSpeechSynthesizer.alloc.initWithVoice(voice_type)
voice.startSpeakingString(text)
while voice.isSpeaking
end
voice = nil
end
end
#------------------------------------------------------------------------------
# gntp
#------------------------------------------------------------------------------
require 'rubygems'
require 'ruby_gntp'
GNTP.notify({
:app_name => "TestMacRuby",
:title => "Voice Name",
:text => vt,
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment