mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-26 04:31:16 +00:00
* Tools/speech/GSSpeechSynthesizer.m: Use object_getClass()
instead of isa. Make exitIfUnneeded: a class method. Reformat code. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@36460 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
c9301f8873
commit
5d5a94d6ac
2 changed files with 85 additions and 66 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2013-04-03 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
|
* Tools/speech/GSSpeechSynthesizer.m: Use object_getClass()
|
||||||
|
instead of isa. Make exitIfUnneeded: a class method. Reformat code.
|
||||||
|
|
||||||
2013-04-03 Fred Kiefer <FredKiefer@gmx.de>
|
2013-04-03 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Source/NSBitmapImageRep+GIF.m (-_bitmapIsGIF:): Prepare for
|
* Source/NSBitmapImageRep+GIF.m (-_bitmapIsGIF:): Prepare for
|
||||||
|
|
|
@ -10,116 +10,130 @@ static int clients;
|
||||||
@implementation GSSpeechSynthesizer
|
@implementation GSSpeechSynthesizer
|
||||||
+ (void)initialize
|
+ (void)initialize
|
||||||
{
|
{
|
||||||
server = [[GSSpeechServer sharedServer] retain];
|
server = [[GSSpeechServer sharedServer] retain];
|
||||||
[[NSNotificationCenter defaultCenter]
|
[[NSNotificationCenter defaultCenter]
|
||||||
addObserver: self
|
addObserver: self
|
||||||
selector: @selector(connectionDied:)
|
selector: @selector(connectionDied:)
|
||||||
name: NSConnectionDidDieNotification
|
name: NSConnectionDidDieNotification
|
||||||
object: nil];
|
object: nil];
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If the remote end exits before freeing the GSSpeechSynthesizer then we need
|
* If the remote end exits before freeing the GSSpeechSynthesizer then we need
|
||||||
* to send it a -release message to make sure it dies.
|
* to send it a -release message to make sure it dies.
|
||||||
*/
|
*/
|
||||||
+ (void)connectionDied: (NSNotification*)aNotification
|
+ (void)connectionDied: (NSNotification*)aNotification
|
||||||
{
|
{
|
||||||
NSEnumerator *e = [[[aNotification object] localObjects] objectEnumerator];
|
NSEnumerator *e = [[[aNotification object] localObjects] objectEnumerator];
|
||||||
for (NSObject *o = [e nextObject] ; nil != o ; o = [e nextObject])
|
for (NSObject *o = [e nextObject] ; nil != o ; o = [e nextObject])
|
||||||
{
|
{
|
||||||
if ([o isKindOfClass: self])
|
if ([o isKindOfClass: self])
|
||||||
{
|
{
|
||||||
[o release];
|
[o release];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* If no clients have been active for some time, kill the speech server to
|
* If no clients have been active for some time, kill the speech server to
|
||||||
* conserve resources.
|
* conserve resources.
|
||||||
*/
|
*/
|
||||||
- (void)exitIfUnneeded: (NSTimer*)sender
|
+ (void)exitIfUnneeded: (NSTimer*)sender
|
||||||
{
|
{
|
||||||
if (clients == 0)
|
if (clients == 0)
|
||||||
{
|
{
|
||||||
exit(0);
|
exit(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)initWithVoice: (NSString*)aVoice
|
- (id)initWithVoice: (NSString*)aVoice
|
||||||
{
|
{
|
||||||
clients++;
|
clients++;
|
||||||
if (nil == (self = [super init])) { return nil; }
|
if (nil == (self = [super init]))
|
||||||
[self setVoice: currentVoice];
|
{
|
||||||
return self;
|
return nil;
|
||||||
|
}
|
||||||
|
[self setVoice: currentVoice];
|
||||||
|
return self;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)init
|
- (id)init
|
||||||
{
|
{
|
||||||
return [self initWithVoice: nil];
|
return [self initWithVoice: nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSString*)voice
|
- (NSString*)voice
|
||||||
{
|
{
|
||||||
return currentVoice;
|
return currentVoice;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (id)delegate
|
- (id)delegate
|
||||||
{
|
{
|
||||||
return delegate;
|
return delegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setDelegate: (id)aDelegate
|
- (void)setDelegate: (id)aDelegate
|
||||||
{
|
{
|
||||||
// Either -retain or -release can throw an exception due to DO.
|
// Either -retain or -release can throw an exception due to DO.
|
||||||
NS_DURING
|
NS_DURING
|
||||||
aDelegate = [aDelegate retain];
|
aDelegate = [aDelegate retain];
|
||||||
NS_HANDLER
|
NS_HANDLER
|
||||||
NS_ENDHANDLER
|
NS_ENDHANDLER
|
||||||
NS_DURING
|
NS_DURING
|
||||||
[delegate release];
|
[delegate release];
|
||||||
NS_HANDLER
|
NS_HANDLER
|
||||||
NS_ENDHANDLER
|
NS_ENDHANDLER
|
||||||
delegate = aDelegate;
|
delegate = aDelegate;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)setVoice: (NSString*)aVoice
|
- (void)setVoice: (NSString*)aVoice
|
||||||
{
|
{
|
||||||
if (nil == aVoice)
|
if (nil == aVoice)
|
||||||
{
|
{
|
||||||
aVoice = [server defaultVoice];
|
aVoice = [server defaultVoice];
|
||||||
}
|
}
|
||||||
ASSIGN(currentVoice, aVoice);
|
ASSIGN(currentVoice, aVoice);
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)startSpeakingString: (NSString*)aString
|
- (BOOL)startSpeakingString: (NSString*)aString
|
||||||
{
|
{
|
||||||
[server setVoice: currentVoice];
|
[server setVoice: currentVoice];
|
||||||
return [server startSpeakingString: aString notifyWhenDone: self];
|
return [server startSpeakingString: aString notifyWhenDone: self];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)didFinishSpeaking: (BOOL)didFinish
|
- (void)didFinishSpeaking: (BOOL)didFinish
|
||||||
{
|
{
|
||||||
// Throw the delegate away if it is throwing exceptions during
|
// Throw the delegate away if it is throwing exceptions during
|
||||||
// notification.
|
// notification.
|
||||||
NS_DURING
|
NS_DURING
|
||||||
[delegate speechSynthesizer: self didFinishSpeaking: didFinish];
|
[delegate speechSynthesizer: self didFinishSpeaking: didFinish];
|
||||||
NS_HANDLER
|
NS_HANDLER
|
||||||
NS_DURING
|
NS_DURING
|
||||||
id d = delegate;
|
id d = delegate;
|
||||||
delegate = nil;
|
delegate = nil;
|
||||||
[d release];
|
[d release];
|
||||||
NS_HANDLER
|
NS_HANDLER
|
||||||
NS_ENDHANDLER
|
NS_ENDHANDLER
|
||||||
NS_ENDHANDLER
|
NS_ENDHANDLER
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)stopSpeaking
|
- (void)stopSpeaking
|
||||||
{
|
{
|
||||||
[server stopSpeaking];
|
[server stopSpeaking];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)dealloc
|
- (void)dealloc
|
||||||
{
|
{
|
||||||
clients--;
|
clients--;
|
||||||
[currentVoice release];
|
[currentVoice release];
|
||||||
if (clients == 0)
|
if (clients == 0)
|
||||||
{
|
{
|
||||||
[NSTimer scheduledTimerWithTimeInterval: 600
|
[NSTimer scheduledTimerWithTimeInterval: 600
|
||||||
target: isa
|
target: object_getClass()
|
||||||
selector: @selector(exitIfUnneeded:)
|
selector: @selector(exitIfUnneeded:)
|
||||||
userInfo: nil
|
userInfo: nil
|
||||||
repeats: NO];
|
repeats: NO];
|
||||||
}
|
}
|
||||||
[super dealloc];
|
[super dealloc];
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
Loading…
Reference in a new issue