---------start ruby-----------------------
class ApplicationController
attr_writer :textField, :stopButton, :startButton
attr_reader :synth, :textField
def init
@synth = NSSpeechSynthesizer.alloc.initWithVoice(nil)
synth.delegate = self
super
end
def sayIt(sender)
unless textField.stringValue.strip.empty?
synth.startSpeakingString(textField.stringValue)
end
@stopButton.enabled = true
@startButton.enabled = false
end
def stopIt(sender)
synth.stopSpeaking
end
private
def speechSynthesizer(sender, didFinishSpeaking: success)
@stopButton.enabled = false
@startButton.enabled = true
end
def awakeFromNib
@stopButton.enabled = false
end
end
----------------end ruby----------------------
----------------start objective-c-------------
// Aaron Hillegass .Copyright 2007
#import <Cocoa/Cocoa.h>
@interface AppController : NSObject {
IBOutlet NSTextField *textField;
NSSpeechSynthesizer *speechSynth;
}
- (IBAction)sayIt:(id)sender;
- (IBAction)stopIt:(id)sender;
@end
@implementation AppController
- (id)init
{
[super init];
NSLog(@"init");
speechSynth = [[NSSpeechSynthesizer alloc] initWithVoice:nil];
return self;
}
- (IBAction)sayIt:(id)sender
{
NSString *string = [textField stringValue];
// Is 'string' zero-length?
if ([string length] == 0) {
return;
}
[speechSynth startSpeakingString:string];
NSLog(@"Have started to say: %@", string);
}
- (IBAction)stopIt:(id)sender
{
NSLog(@"stopping");
[speechSynth stopSpeaking];
}
@end
----------------end objective-c---------------
----------------start nu----------------------
(load "Nu:nu") ;; basics
(load "Nu:cocoa") ;; cocoa definitions
(load "Nu:menu") ;; menu generation
(class AppController is NSObject
(ivar (id) textField
(id) colorWell
(id) speechSynth)
(- (id) init is
(super init)
(set @speechSynth ((NSSpeechSynthesizer alloc) initWithVoice:nil))
self)
(- awakeFromNib is
(@colorWell setColor:(@textField textColor)))
(- changeTextColor:(id)sender is
(@textField setTextColor:(@colorWell color)))
(- sayIt:(id)sender is
(@speechSynth startSpeakingString:(@textField stringValue)))
(- stopIt:(id)sender is
(@speechSynth stopSpeaking)))
((NSApplication sharedApplication) activateIgnoringOtherApps:YES)
(NSApplicationMain 0 nil)
----------------end nu------------------------