From: Justin S. <sto...@gm...> - 2008-02-15 03:07:28
|
I'm trying to port a simple objective-c application (from a book on cocoa in os x) to Ruby in Xcode. Basically the application takes a line of text and then says the line (out loud). This all works fine but I'm having trouble figuring out how to do the delegate to make the stop button disable itself when the app finishes saying the line. Here's the code: require 'osx/cocoa' include OSX class Speak < NSObject ib_outlets :textField, :stopButton def initialize @speechSynth = NSSpeechSynthesizer.alloc().initWithVoice_(nil) @speechSynth.setDelegate_(self) end ib_action :say do |sender| blah = @textField.stringValue() if blah.empty? return end @stopButton.setEnabled_(true) if (rand(10)+1) == 1 @speechSynth.startSpeakingString_("I'm not going to say that") else @speechSynth.startSpeakingString_(blah) end NSLog("Have started to say: #{blah}\n") end ib_action :stop do |sender| NSLog("Stopping.") @speechSynth.stopSpeaking end def didFinishSpeaking(sender) NSLog("Finished Speaking.") @stopButton.setDisabled_(true) end end It compiles and runs fine. The only thing that doesn't work is didFinishSpeaking is not called by @speechSynth when it finishes speaking. Any ideas on what I'm doing wrong? |