Add plugins.

This commit is contained in:
Gregory John Casamento 2020-02-10 10:27:20 -05:00
parent 5b96ad6692
commit 49b36d7631
15 changed files with 222 additions and 11 deletions

View file

@ -108,7 +108,7 @@ BOOL _serverLaunchTested = NO;
- (void) processNotification: (NSNotification *)note
{
NSString *word = (NSString *)[note object];
NSLog(@"Got notification");
if (_listensInForegroundOnly)
{
if (_appInForeground == NO)

View file

@ -6,6 +6,7 @@ VERSION = 0.1
# This is an app not a tool because, eventually, it will present the user
# interface for the GUI part of the speech engine.
APP_NAME = GSSpeechRecognitionServer
SUBPROJECTS = Plugins
GSSpeechRecognitionServer_LANGUAGES = English
@ -14,13 +15,17 @@ GSSpeechRecognitionServer_OBJC_FILES = \
GSSpeechRecognitionServer.m \
main.m
GSSpeechRecognitionServer_RESOURCE_FILES = \
Plugins/Pocketsphinx/PocketSphinx.recognizer
# Add includes and link dirs....
GSSpeechRecognitionServer_OBJC_FILES += $(RECOGNIZER_ENGINE_CLASS)
GSSpeechRecognitionServer_INCLUDE_DIRS += $(RECOGNIZER_BASE_CFLAGS) \
GSSpeechRecognitionServer_INCLUDE_DIRS += \
-I../../Headers \
-I../../Headers/Additions
GSSpeechRecognitionServer_LIB_DIRS += -L../../Source/$(GNUSTEP_OBJ_DIR) \
-L/usr/local/lib -lgnustep-gui \
$(RECOGNIZER_BASE_LIBS)
-L/usr/local/lib -lgnustep-gui
include $(GNUSTEP_MAKEFILES)/aggregate.make
include $(GNUSTEP_MAKEFILES)/application.make

View file

@ -35,7 +35,9 @@
@interface GSSpeechRecognitionServer : NSObject
{
GSSpeechRecognitionEngine *_engine;
NSMutableArray *_blocking;
NSMutableArray *_blocking;
NSMutableArray *bundles;
NSMutableArray *pluginNames;
}
/**
@ -47,6 +49,7 @@
- (void) addToBlockingRecognizers: (NSString *)s;
- (void) removeFromBlockingRecognizers: (NSString *)s;
- (BOOL) isBlocking: (NSString *)s;
- (GSSpeechRecognitionEngine *) defaultEngine;
// Connection...
- (void) addClient;

View file

@ -96,14 +96,119 @@ static int _clients = 0;
_clients++;
}
- (BOOL) bundlePathIsLoaded: (NSString *)path
{
int i = 0;
NSBundle *bundle;
for (i = 0; i < [bundles count]; i++)
{
bundle = [bundles objectAtIndex: i];
if ([path isEqualToString: [bundle bundlePath]] == YES)
{
return YES;
}
}
return NO;
}
- (BOOL) loadPlugin: (NSString*)path
{
NSBundle *bundle;
NSString *className;
// NSObject *plugin;
// Class pluginClass;
if([self bundlePathIsLoaded: path])
{
NSLog(@"bundle has already been loaded");
return NO;
}
bundle = [NSBundle bundleWithPath: path];
if (bundle == nil)
{
NSLog(@"Could not load bundle");
return NO;
}
className = [[bundle infoDictionary] objectForKey: @"NSPrincipalClass"];
if (className == nil)
{
NSLog(@"No plugin class in plist");
return NO;
}
/*
pluginClass = [bundle classNamed: className];
if (pluginClass == 0)
{
NSLog(@"Could not load bundle princpal class: %@", className);
return NO;
}
plugin = [[pluginClass alloc] init];
if ([plugin isKindOfClass: [GSSpeechRecognitionEngine class]] == NO)
{
NSLog(@"bundle contains wrong type of class");
RELEASE(plugin);
return NO;
}
*/
// add to the bundles list...
[bundles addObject: bundle];
// manage plugin data.
[pluginNames addObject: className];
// RELEASE(plugin);
return YES;
}
- (GSSpeechRecognitionEngine *) defaultEngine
{
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSString *className = [defaults stringForKey: @"GSDefaultSpeechRecognitionEngine"];
if ([pluginNames containsObject: className])
{
_engineClass = NSClassFromString(className);
}
else
{
_engineClass = NSClassFromString(@"PocketsphinxSpeechRecognitionEngine");
}
return [[engineClass alloc] init];
}
- (id)init
{
NSArray *array = nil;
if (nil == (self = [super init]))
{
return nil;
}
_engine = [GSSpeechRecognitionEngine defaultSpeechRecognitionEngine];
// pluginsDict = [[NSMutableDictionary alloc] init];
// plugins = [[NSMutableArray alloc] init];
bundles = [[NSMutableArray alloc] init];
pluginNames = [[NSMutableArray alloc] init];
array = [[NSBundle mainBundle] pathsForResourcesOfType: @"recognizer"
inDirectory: nil];
if ([array count] > 0)
{
unsigned index;
array = [array sortedArrayUsingSelector: @selector(compare:)];
for (index = 0; index < [array count]; index++)
{
[self loadPlugin: [array objectAtIndex: index]];
}
}
_engine = [self defaultEngine];
if (nil == _engine)
{
[self release];

View file

@ -0,0 +1,36 @@
# Author: Gregory John Casamento
# Date: 2020
#
# This file is part of GNUstep.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111 USA.
#
PACKAGE_NAME = recognizer
include $(GNUSTEP_MAKEFILES)/common.make
#
# Each palette is a subproject
#
SUBPROJECTS = \
Pocketsphinx
-include GNUmakefile.preamble
-include GNUmakefile.local
include $(GNUSTEP_MAKEFILES)/aggregate.make
-include GNUmakefile.postamble

View file

@ -0,0 +1,52 @@
# GNUmakefile
#
# Copyright (C) 1999 Free Software Foundation, Inc.
#
# Author: Richard Frith-Macdonald <richard@brainstorm.co.uk>
# Date: 1999
#
# This file is part of GNUstep.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
PACKAGE_NAME = recognizer
include $(GNUSTEP_MAKEFILES)/common.make
include ../../../../config.make
BUNDLE_NAME = PocketSphinx
BUNDLE_EXTENSION = .recognizer
PocketSphinx_PRINCIPAL_CLASS = PocketsphinxSpeechRecognitionEngine
PocketSphinx_OBJC_FILES = PocketsphinxSpeechRecognitionEngine.m
PocketSphinx_RESOURCE_FILES =
PocketSphinx_STANDARD_INSTALL = no
PocketSphinx_INCLUDE_DIRS += $(RECOGNIZER_BASE_CFLAGS) \
-I../../ \
-I../../../Headers \
-I../../../Headers/Additions
PocketSphinx_LIB_DIRS += -L../../../Source/$(GNUSTEP_OBJ_DIR) \
-L/usr/local/lib -lgnustep-gui \
$(RECOGNIZER_BASE_LIBS)
-include GNUmakefile.preamble
-include GNUmakefile.local
include $(GNUSTEP_MAKEFILES)/bundle.make
-include GNUmakefile.postamble

View file

@ -0,0 +1,6 @@
{
NOTE = "Automatically generated, do not edit!";
NSExecutable = "PocketSphinx";
NSMainNibFile = "";
NSPrincipalClass = "PocketsphinxSpeechRecognitionEngine";
}

View file

@ -0,0 +1 @@
OLD_GNUSTEP_STAMP_ASTRING = _PocketsphinxSpeechRecognitionEngine-

View file

@ -223,6 +223,7 @@ static const arg_t cont_args_def[] = {
@end
/*
@implementation GSSpeechRecognitionEngine (Pocketsphinx)
+ (GSSpeechRecognitionEngine*)defaultSpeechRecognitionEngine
@ -231,3 +232,4 @@ static const arg_t cont_args_def[] = {
}
@end
*/

4
configure vendored
View file

@ -5738,10 +5738,10 @@ fi
done
if test $have_pocketsphinx = yes -a $have_speech_recognizer = yes -a $enable_speech_recognizer = yes; then
BUILD_SPEECH_RECOGNIZER="speech_recognizer"
BUILD_SPEECH_RECOGNIZER="recognizer"
RECOGNIZER_BASE_LIBS=`pkg-config --libs pocketsphinx sphinxbase`
RECOGNIZER_BASE_CFLAGS=`pkg-config --cflags pocketsphinx sphinxbase`
RECOGNIZER_ENGINE_CLASS=PocketsphinxSpeechRecognitionEngine.m
# RECOGNIZER_ENGINE_CLASS=PocketsphinxSpeechRecognitionEngine.m
fi

View file

@ -550,10 +550,11 @@ BUILD_SPEECH_RECOGNIZER=
AC_CHECK_LIB(pocketsphinx, ps_start_utt, have_speech_recognizer=yes, have_speech_recognizer=no)
AC_CHECK_HEADERS(pocketsphinx/pocketsphinx_export.h, have_pocketsphinx=yes, have_pocketsphinx=no)
if test $have_pocketsphinx = yes -a $have_speech_recognizer = yes -a $enable_speech_recognizer = yes; then
BUILD_SPEECH_RECOGNIZER="speech_recognizer"
BUILD_SPEECH_RECOGNIZER="recognizer"
BUILD_RECOGNIZER_PLUGIN="pocketsphinx"
RECOGNIZER_BASE_LIBS=`pkg-config --libs pocketsphinx sphinxbase`
RECOGNIZER_BASE_CFLAGS=`pkg-config --cflags pocketsphinx sphinxbase`
RECOGNIZER_ENGINE_CLASS=PocketsphinxSpeechRecognitionEngine.m
# RECOGNIZER_ENGINE_CLASS=PocketsphinxSpeechRecognitionEngine.m
fi
AC_SUBST(BUILD_SPEECH_RECOGNIZER)
AC_SUBST(RECOGNIZER_BASE_LIBS)