mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 19:01:15 +00:00
Changes to support multiple connections.
This commit is contained in:
parent
4b1d3c679f
commit
031868f73e
7 changed files with 45 additions and 35 deletions
|
@ -47,6 +47,7 @@ extern "C" {
|
|||
BOOL _blocksOtherRecognizers;
|
||||
BOOL _listensInForegroundOnly;
|
||||
BOOL _appInForeground; // private
|
||||
BOOL _isListening;
|
||||
}
|
||||
|
||||
// Initialize
|
||||
|
|
|
@ -46,6 +46,7 @@ BOOL _serverLaunchTested = NO;
|
|||
- (void) addToBlockingRecognizers: (NSString *)s;
|
||||
- (void) removeFromBlockingRecognizers: (NSString *)s;
|
||||
- (BOOL) isBlocking: (NSString *)s;
|
||||
- (void) addClient;
|
||||
@end
|
||||
|
||||
@implementation NSSpeechRecognizer
|
||||
|
@ -54,6 +55,12 @@ BOOL _serverLaunchTested = NO;
|
|||
{
|
||||
if (self == [NSSpeechRecognizer class])
|
||||
{
|
||||
// Test for an existant server...
|
||||
_speechRecognitionServer =
|
||||
[NSConnection rootProxyForConnectionWithRegisteredName: SPEECH_RECOGNITION_SERVER
|
||||
host: nil];
|
||||
|
||||
// if none exists, start one. We will connect with it in init.
|
||||
if (nil == _speechRecognitionServer)
|
||||
{
|
||||
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
|
||||
|
@ -68,6 +75,11 @@ BOOL _serverLaunchTested = NO;
|
|||
{
|
||||
NSString *word = (NSString *)[note object];
|
||||
|
||||
if (_isListening == NO)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_listensInForegroundOnly)
|
||||
{
|
||||
if (_appInForeground == NO)
|
||||
|
@ -164,6 +176,9 @@ BOOL _serverLaunchTested = NO;
|
|||
_serverLaunchTested = YES;
|
||||
}
|
||||
}
|
||||
|
||||
[_speechRecognitionServer addClient]; // do this to update the client count;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
|
@ -238,11 +253,11 @@ BOOL _serverLaunchTested = NO;
|
|||
// Listening
|
||||
- (void) startListening
|
||||
{
|
||||
[_speechRecognitionServer startListening];
|
||||
_isListening = YES; // [_speechRecognitionServer startListening];
|
||||
}
|
||||
|
||||
- (void) stopListening
|
||||
{
|
||||
[_speechRecognitionServer stopListening];
|
||||
_isListening = NO; // [_speechRecognitionServer stopListening];
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -33,8 +33,8 @@
|
|||
*/
|
||||
@interface GSSpeechRecognitionEngine : NSObject
|
||||
|
||||
- (void) startListening;
|
||||
- (void) stopListening;
|
||||
- (void) start;
|
||||
- (void) stop;
|
||||
|
||||
@end
|
||||
|
||||
|
|
|
@ -34,16 +34,16 @@
|
|||
return AUTORELEASE([[self alloc] init]);
|
||||
}
|
||||
|
||||
- (void) startListening
|
||||
{
|
||||
}
|
||||
|
||||
- (void) stopListening
|
||||
{
|
||||
}
|
||||
|
||||
- (void) recognize
|
||||
{
|
||||
}
|
||||
|
||||
- (void) start
|
||||
{
|
||||
}
|
||||
|
||||
- (void) stop
|
||||
{
|
||||
}
|
||||
|
||||
@end
|
||||
|
|
|
@ -43,13 +43,11 @@
|
|||
*/
|
||||
+ (id)sharedServer;
|
||||
|
||||
// Start and stop processing....
|
||||
- (void) startListening;
|
||||
- (void) stopListening;
|
||||
|
||||
// Add or remove from blocking list...
|
||||
- (void) addToBlockingRecognizers: (NSString *)s;
|
||||
- (void) removeFromBlockingRecognizers: (NSString *)s;
|
||||
- (BOOL) isBlocking: (NSString *)s;
|
||||
|
||||
// Connection...
|
||||
- (void) addClient;
|
||||
@end
|
||||
|
|
|
@ -45,7 +45,7 @@ static int _clients = 0;
|
|||
_clients--;
|
||||
}
|
||||
|
||||
if(_clients <= 0)
|
||||
if(_clients == 0)
|
||||
{
|
||||
NSLog(@"Client count is zero, exiting");
|
||||
exit(0);
|
||||
|
@ -87,11 +87,15 @@ static int _clients = 0;
|
|||
|
||||
+ (id)sharedServer
|
||||
{
|
||||
_clients++;
|
||||
NSLog(@"NSSpeechRecognizer server connection count = %d after connection", _clients);
|
||||
return _sharedInstance;
|
||||
}
|
||||
|
||||
- (void) addClient
|
||||
{
|
||||
_clients++;
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
if (nil == (self = [super init]))
|
||||
|
@ -107,7 +111,8 @@ static int _clients = 0;
|
|||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"Got engine %@", _engine);
|
||||
NSLog(@"Got engine starting... %@", _engine);
|
||||
[_engine start];
|
||||
}
|
||||
|
||||
_blocking = [[NSMutableArray alloc] initWithCapacity: 10]; // 10 seems reasonable...
|
||||
|
@ -117,21 +122,12 @@ static int _clients = 0;
|
|||
|
||||
- (void) dealloc
|
||||
{
|
||||
[_engine stop];
|
||||
RELEASE(_engine);
|
||||
RELEASE(_blocking);
|
||||
[super dealloc];
|
||||
}
|
||||
|
||||
- (void) startListening
|
||||
{
|
||||
[_engine startListening];
|
||||
}
|
||||
|
||||
- (void) stopListening
|
||||
{
|
||||
[_engine stopListening];
|
||||
}
|
||||
|
||||
- (void) addToBlockingRecognizers: (NSString *)s
|
||||
{
|
||||
[_blocking addObject: s];
|
||||
|
|
|
@ -168,7 +168,7 @@ static const arg_t cont_args_def[] = {
|
|||
if (in_speech && !utt_started)
|
||||
{
|
||||
utt_started = YES;
|
||||
NSDebugLog(@"Listening...");
|
||||
NSLog(@"Listening...");
|
||||
}
|
||||
|
||||
if (!in_speech && utt_started)
|
||||
|
@ -183,7 +183,7 @@ static const arg_t cont_args_def[] = {
|
|||
[self performSelectorOnMainThread: @selector(_recognizedWord:)
|
||||
withObject: recognizedString
|
||||
waitUntilDone: NO];
|
||||
NSDebugLog(@"RECOGNIZED WORD: %s", hyp);
|
||||
NSLog(@"Word: %s", hyp);
|
||||
}
|
||||
|
||||
if (ps_start_utt(ps) < 0)
|
||||
|
@ -202,20 +202,20 @@ static const arg_t cont_args_def[] = {
|
|||
ad_close(ad);
|
||||
}
|
||||
|
||||
- (void) startListening
|
||||
- (void) start
|
||||
{
|
||||
_listeningThread =
|
||||
[[NSThread alloc] initWithTarget: self
|
||||
selector: @selector(recognize)
|
||||
object: nil];
|
||||
[_listeningThread setName: @"Speech Recognition Loop"];
|
||||
NSDebugLog(@"Thread info for speech recognition server %@", _listeningThread);
|
||||
NSLog(@"Starting - Thread info for speech recognition server %@", _listeningThread);
|
||||
[_listeningThread start];
|
||||
}
|
||||
|
||||
- (void) stopListening
|
||||
- (void) stop
|
||||
{
|
||||
NSDebugLog(@"Stop listening thread %@", _listeningThread);
|
||||
NSLog(@"Stop listening thread %@", _listeningThread);
|
||||
[_listeningThread cancel];
|
||||
RELEASE(_listeningThread);
|
||||
_listeningThread = nil;
|
||||
|
|
Loading…
Reference in a new issue