Clean build for NSSpeechRecognizer

This commit is contained in:
Gregory John Casamento 2020-02-01 04:16:48 -05:00
parent a880154841
commit 9ee975860a
4 changed files with 128 additions and 42 deletions

View file

@ -36,12 +36,20 @@ extern "C" {
@protocol NSSpeechRecognizerDelegate;
@interface NSSpeechRecognizer : NSObject
{
id<NSSpeechRecognizerDelegate> _delegate;
NSArray *_commands;
NSString *_displayCommandsTitle;
BOOL _blocksOtherRecognizers;
BOOL _listensInForegroundOnly;
}
// Initialize
- (instancetype) init;
- (id<NSSpeechRecognizerDelegate>) delegate;
- (void) setDelegate: (id<NSSpeechRecognizerDelegate>) delegate;
// Configuring...
- (NSArray *) commands;
- (void) setCommands: (NSArray *)commands;
@ -50,7 +58,7 @@ extern "C" {
- (void) setDisplayCommandsTitle: (NSString *)displayCommandsTitle;
- (BOOL) listensInForegroundOnly;
- (void) setListensInForgroundOnly: (BOOL)listensInForgroundOnly;
- (void) setListensInForegroundOnly: (BOOL)listensInForegroundOnly;
- (BOOL) blocksOtherRecognizers;
- (void) setBlocksOtherRecognizers: (BOOL)blocksOtherRecognizers;

View file

@ -36,7 +36,7 @@ typedef enum
NSSpeechImmediateBoundary = 0,
NSSpeechWordBoundary,
NSSpeechSentenceBoundary
}
}
NSSpeechBoundary;
// forward declarations...
@ -184,3 +184,4 @@ extern NSString *NSSpeechDictionaryEntryPhonemes;
@end
#endif // _GNUstep_H_NSSpeechSynthesizer

View file

@ -26,5 +26,81 @@
@implementation NSSpeechRecognizer
+ (void) initialize
{
}
// Initialize
- (instancetype) init
{
self = [super init];
if (self != nil)
{
}
return self;
}
- (id<NSSpeechRecognizerDelegate>) delegate
{
return _delegate;
}
- (void) setDelegate: (id<NSSpeechRecognizerDelegate>)delegate
{
_delegate = delegate;
}
// Configuring...
- (NSArray *) commands
{
return _commands;
}
- (void) setCommands: (NSArray *)commands
{
ASSIGNCOPY(_commands, commands);
}
- (NSString *) displayCommandsTitle
{
return _displayCommandsTitle;
}
- (void) setDisplayCommandsTitle: (NSString *)displayCommandsTitle
{
ASSIGNCOPY(_displayCommandsTitle, displayCommandsTitle);
}
- (BOOL) listensInForegroundOnly
{
return _listensInForegroundOnly;
}
- (void) setListensInForegroundOnly: (BOOL)listensInForegroundOnly
{
_listensInForegroundOnly = listensInForegroundOnly;
}
- (BOOL) blocksOtherRecognizers
{
return _blocksOtherRecognizers;
}
- (void) setBlocksOtherRecognizers: (BOOL)blocksOtherRecognizers
{
_blocksOtherRecognizers = blocksOtherRecognizers;
}
// Listening
- (void) startListening
{
// Do nothing...
}
- (void) stopListening
{
// Do nothing...
}
@end

View file

@ -102,58 +102,59 @@ static Class NSSpeechSynthesizerClass;
- (NSSpeechSynthesizer*)newSynthesizer;
@end
@implementation NSSpeechSynthesizer
@implementation NSSpeechSynthesizer
- (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];
}
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];
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];
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