Add files

This commit is contained in:
Gregory John Casamento 2020-02-03 01:02:50 -05:00
parent 886cb4d0e8
commit fbcc8c6ae4
5 changed files with 114 additions and 1 deletions

View file

@ -7,6 +7,10 @@
* in future if pluggable speech engines are considered beneficial.
*/
@interface GSSpeechRecognitionEngine : NSObject
- (void) startListening;
- (void) stopListening;
@end
@interface NSObject (GSSpeechRecognitionEngineDelegate)

View file

@ -44,4 +44,13 @@ static GSSpeechRecognitionServer *sharedInstance;
{
return [[GSSpeechRecognizer new] autorelease];
}
- (void) startListening
{
}
- (void) stopListening
{
}
@end

View file

@ -0,0 +1,12 @@
#import "GSSpeechRecognitionServer.h"
#import <AppKit/NSSpeechRecognizer.h>
@interface GSSpeechRecognizer : NSSpeechRecognizer {
NSString *currentVoice;
id delegate;
}
- (id)init;
- (id)delegate;
- (void)setDelegate: (id)aDelegate;
@end

View file

@ -0,0 +1,79 @@
#import "GSSpeechRecognizer.h"
static GSSpeechRecognitionServer *server;
static int clients;
@interface GSSpeechRecognizer (Private)
+ (void)connectionDied: (NSNotification*)aNotification;
@end
@implementation GSSpeechRecognizer
+ (void)initialize
{
server = [[GSSpeechRecognitionServer sharedServer] retain];
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(connectionDied:)
name: NSConnectionDidDieNotification
object: nil];
}
/**
* If the remote end exits before freeing the GSSpeechRecognizer then we need
* to send it a -release message to make sure it dies.
*/
+ (void)connectionDied: (NSNotification*)aNotification
{
NSEnumerator *e = [[[aNotification object] localObjects] objectEnumerator];
NSObject *o = nil;
for (o = [e nextObject] ; nil != o ; o = [e nextObject])
{
if ([o isKindOfClass: self])
{
[o release];
}
}
}
/**
* If no clients have been active for some time, kill the speech server to
* conserve resources.
*/
+ (void)exitIfUnneeded: (NSTimer*)sender
{
if (clients == 0)
{
exit(0);
}
}
- (id)init
{
self = [super init];
return self;
}
- (void)dealloc
{
clients--;
if (clients == 0)
{
[NSTimer scheduledTimerWithTimeInterval: 600
target: object_getClass(self)
selector: @selector(exitIfUnneeded:)
userInfo: nil
repeats: NO];
}
[super dealloc];
}
- (void) setDelegate: (id)delegate
{
}
- (id) delegate
{
return nil;
}
@end

View file

@ -1,5 +1,5 @@
#import "GSSpeechRecognitionEngine.h"
// #include <pocketsphinx/pocketsphinx.h>
#include <pocketsphinx/pocketsphinx.h>
/**
* Implementation of a speech engine using pocketsphinx. This should be the default
@ -20,6 +20,15 @@
if (nil == (self = [super init])) { return nil; }
return self;
}
- (void) startListening
{
}
- (void) stopListening
{
}
@end
@implementation GSSpeechRecognitionEngine (Pocketsphinx)