diff --git a/ChangeLog b/ChangeLog index d7b57e757..a6a4c2144 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2009-06-05 18:21-EDT Gregory John Casamento + + * Headers/AppKit/NSSpeechSynthesizer.h: + * Source/NSSpeechSynthesizer.m: Implementation of + NSSpeechSynthesizer. + Patch by David Chisnall + 2009-06-02 Fred Kiefer * Source/NSDocument.m (-runModalSavePanelForSaveOperation:...): @@ -62,7 +69,8 @@ 2009-04-27 Fred Kiefer - * Source/NSBezierPath.m (-appendBezierPathWithRoundedRect:xRadius:yRadius:): + * Source/NSBezierPath.m (-appendBezierPathWithRoundedRect:xRadius: + yRadius:): Small rearangment of code. Patch by Fred Morcos diff --git a/Headers/AppKit/NSSpeechSynthesizer.h b/Headers/AppKit/NSSpeechSynthesizer.h index 949900b31..1109db3c0 100644 --- a/Headers/AppKit/NSSpeechSynthesizer.h +++ b/Headers/AppKit/NSSpeechSynthesizer.h @@ -95,17 +95,6 @@ extern NSString *NSSpeechDictionaryEntryPhonemes; // class declaration... @interface NSSpeechSynthesizer : NSObject -{ - NSString *_voice; - BOOL _usesFeedbackWindow; - float _rate; - float _volume; - id _delegate; - NSMutableArray *_dictionaries; - NSMutableDictionary *_properties; - BOOL _isSpeaking; - id _module; -} // init... - (id) initWithVoice: (NSString *)voice; diff --git a/Source/NSSpeechSynthesizer.m b/Source/NSSpeechSynthesizer.m index 836e62ab0..4c6b8da9c 100644 --- a/Source/NSSpeechSynthesizer.m +++ b/Source/NSSpeechSynthesizer.m @@ -29,7 +29,10 @@ #include #include #include +#include #include +#include +#include "AppKit/NSWorkspace.h" #include "AppKit/NSSpeechSynthesizer.h" // Keys for properties... @@ -83,53 +86,106 @@ NSString *NSSpeechDictionaryAbreviations = @"NSSpeechDictionaryAbreviations"; NSString *NSSpeechDictionaryEntrySpelling = @"NSSpeechDictionaryEntrySpelling"; NSString *NSSpeechDictionaryEntryPhonemes = @"NSSpeechDictionaryEntryPhonemes"; -// class declaration... +// Speech daemon +static id server; +// Flag indicating whether we should wait for the daemon to finish launching. +static BOOL serverLaunchTested; +// Class of the NSSpeechSynthesizer +static Class NSSpeechSynthesizerClass; +// Informal protocol used for the server. +@interface NSObject (GSSpeechServer) +- (NSSpeechSynthesizer*)newSynthesizer; +@end + @implementation NSSpeechSynthesizer -// init... - (id) initWithVoice: (NSString *)voice { return self; } ++ (void)initialize +{ + NSSpeechSynthesizerClass = [NSSpeechSynthesizer class]; + server = [[NSConnection rootProxyForConnectionWithRegisteredName: @"GSSpeechServer" + host: nil] retain]; + if (nil == server) + { + NSWorkspace *ws = [NSWorkspace sharedWorkspace]; + [ws launchApplication: @"GSSpeechServer" + showIcon: NO + autolaunch: NO]; + } +} ++ (BOOL)isAnyApplicationSpeaking +{ + return [server isSpeaking]; +} +// Never really allocate one of these. ++ (id)allocWithZone: (NSZone*)aZone +{ + if (self == NSSpeechSynthesizerClass) + { + if (nil == server && !serverLaunchTested) + { + unsigned int i=0; + // Wait for up to five seconds for the server to launch, then give up. + for (i=0 ; i<50 ; i++) + { + server = + [[NSConnection rootProxyForConnectionWithRegisteredName: + @"GSSpeechServer" + host: nil] + retain]; + if (nil != server) + { + break; + } + [NSThread sleepForTimeInterval: 0.1]; + } + // Set a flag so we don't bother waiting for the speech server to + // launch the next time if it didn't work this time. + serverLaunchTested = YES; + } + // If there is no server, this will return nil + return [server newSynthesizer]; + } + return [super allocWithZone: aZone]; +} // configuring speech synthesis - (BOOL) usesFeebackWindow { - return _usesFeedbackWindow; + return NO; } - (void) setUsesFeebackWindow: (BOOL)flag { - _usesFeedbackWindow = flag; } - (NSString *) voice { - return _voice; + return nil; } - (void) setVoice: (NSString *)voice { - ASSIGN(_voice, voice); } - (float) rate { - return _rate; + return 0; } - (void) setRate: (float)rate { - _rate = rate; } - (float) volume { - return _volume; + return 0; } - (void) setVolume: (float)volume { - _volume = volume; } - (void) addSpeechDictionary: (NSDictionary *)speechDictionary @@ -145,18 +201,16 @@ NSString *NSSpeechDictionaryEntryPhonemes = @"NSSpeechDictionaryEntryPhonemes"; forProperty: (NSString *)property error: (NSError **)error { - [self subclassResponsibility: _cmd]; return nil; } - (id) delegate { - return _delegate; + return nil; } - (void) setDelegate: (id)delegate { - _delegate = delegate; } // Getting information... @@ -172,57 +226,43 @@ NSString *NSSpeechDictionaryEntryPhonemes = @"NSSpeechDictionaryEntryPhonemes"; + (NSString *) defaultVoice { - [self subclassResponsibility: _cmd]; return nil; } -// Getting state... -+ (BOOL) isAnyApplicationSpeaking -{ - return NO; -} - // Synthesizing.. - (BOOL) isSpeaking { - return _isSpeaking; + return NO; } - (BOOL) startSpeakingString: (NSString *)text { - [self subclassResponsibility: _cmd]; return NO; } - (BOOL) startSpeakingString: (NSString *)text toURL: (NSURL *)url { - [self subclassResponsibility: _cmd]; return NO; } - (void) stopSpeaking { - [self subclassResponsibility: _cmd]; } - (void) stopSpeakingAtBoundary: (NSSpeechBoundary)boundary { - [self subclassResponsibility: _cmd]; } - (void) pauseSpeakingAtBoundary: (NSSpeechBoundary)boundary { - [self subclassResponsibility: _cmd]; } - (void) continueSpeaking { - [self subclassResponsibility: _cmd]; } - (NSString *) phonemesFromText: (NSString *)text { - [self subclassResponsibility: _cmd]; return nil; } @end