mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 20:40:57 +00:00
Add code to configure.ac to compile speech recognition
This commit is contained in:
parent
36343b81b1
commit
2b565697e5
4 changed files with 180 additions and 80 deletions
|
@ -28,7 +28,7 @@ include ../config.make
|
|||
|
||||
include ../Version
|
||||
|
||||
SUBPROJECTS = $(BUILD_SPEECH) $(BUILD_SOUND)
|
||||
SUBPROJECTS = $(BUILD_SPEECH) $(BUILD_SOUND) $(BUILD_SPEECH_RECOGNITION)
|
||||
TOOL_NAME = make_services set_show_service gopen gclose gcloseall
|
||||
SERVICE_NAME = GSspell
|
||||
|
||||
|
|
|
@ -8,114 +8,119 @@ cst_voice *register_cmu_us_kal16();
|
|||
* for resource-constrained platforms.
|
||||
*/
|
||||
@interface FliteSpeechEngine : GSSpeechEngine {
|
||||
/** The audio device used for sound output. */
|
||||
cst_audiodev *ad;
|
||||
/** The current voice. Only one supported at the moment. */
|
||||
cst_voice *v;
|
||||
/** Flag set to tell the playback thread to exit. */
|
||||
volatile BOOL shouldEndSpeaking;
|
||||
/** Flag indicating whether the engine is currently speaking. */
|
||||
volatile BOOL isSpeaking;
|
||||
/** The audio device used for sound output. */
|
||||
cst_audiodev *ad;
|
||||
/** The current voice. Only one supported at the moment. */
|
||||
cst_voice *v;
|
||||
/** Flag set to tell the playback thread to exit. */
|
||||
volatile BOOL shouldEndSpeaking;
|
||||
/** Flag indicating whether the engine is currently speaking. */
|
||||
volatile BOOL isSpeaking;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation FliteSpeechEngine
|
||||
+ (void)initialize
|
||||
{
|
||||
flite_init();
|
||||
|
||||
flite_init();
|
||||
}
|
||||
|
||||
- (id)init
|
||||
{
|
||||
if (nil == (self = [super init])) { return nil; }
|
||||
|
||||
// Only one voice supported by flite unless others are compiled in.
|
||||
v = register_cmu_us_kal16();
|
||||
if (NULL == v)
|
||||
{
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
|
||||
// Each wave should be the same format.
|
||||
cst_wave *w = flite_text_to_wave("test", v);
|
||||
ad = audio_open(w->sample_rate, w->num_channels, CST_AUDIO_LINEAR16);
|
||||
delete_wave(w);
|
||||
if (NULL == ad)
|
||||
{
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
return self;
|
||||
if (nil == (self = [super init])) { return nil; }
|
||||
|
||||
// Only one voice supported by flite unless others are compiled in.
|
||||
v = register_cmu_us_kal16();
|
||||
if (NULL == v)
|
||||
{
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
|
||||
// Each wave should be the same format.
|
||||
cst_wave *w = flite_text_to_wave("test", v);
|
||||
ad = audio_open(w->sample_rate, w->num_channels, CST_AUDIO_LINEAR16);
|
||||
delete_wave(w);
|
||||
if (NULL == ad)
|
||||
{
|
||||
[self release];
|
||||
return nil;
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)sayString: (NSArray*)args
|
||||
{
|
||||
id pool = [NSAutoreleasePool new];
|
||||
NSString *aString = [args objectAtIndex: 0];
|
||||
int i,n,r;
|
||||
int num_shorts;
|
||||
BOOL didFinish = YES;
|
||||
cst_wave *w = flite_text_to_wave([aString UTF8String], v);
|
||||
|
||||
num_shorts = w->num_samples * w->num_channels;
|
||||
for (i=0; i < num_shorts; i += r/2)
|
||||
{
|
||||
if (num_shorts > i+CST_AUDIOBUFFSIZE)
|
||||
{
|
||||
n = CST_AUDIOBUFFSIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
n = num_shorts-i;
|
||||
}
|
||||
r = audio_write(ad, &w->samples[i], n*2);
|
||||
if (shouldEndSpeaking)
|
||||
{
|
||||
didFinish = NO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
isSpeaking = NO;
|
||||
NS_DURING
|
||||
[[args objectAtIndex: 1] didFinishSpeaking: didFinish];
|
||||
NS_HANDLER
|
||||
NS_ENDHANDLER
|
||||
[args release];
|
||||
[pool release];
|
||||
delete_wave(w);
|
||||
id pool = [NSAutoreleasePool new];
|
||||
NSString *aString = [args objectAtIndex: 0];
|
||||
int i,n,r;
|
||||
int num_shorts;
|
||||
BOOL didFinish = YES;
|
||||
cst_wave *w = flite_text_to_wave([aString UTF8String], v);
|
||||
|
||||
num_shorts = w->num_samples * w->num_channels;
|
||||
for (i=0; i < num_shorts; i += r/2)
|
||||
{
|
||||
if (num_shorts > i+CST_AUDIOBUFFSIZE)
|
||||
{
|
||||
n = CST_AUDIOBUFFSIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
n = num_shorts-i;
|
||||
}
|
||||
r = audio_write(ad, &w->samples[i], n*2);
|
||||
if (shouldEndSpeaking)
|
||||
{
|
||||
didFinish = NO;
|
||||
break;
|
||||
}
|
||||
}
|
||||
isSpeaking = NO;
|
||||
NS_DURING
|
||||
[[args objectAtIndex: 1] didFinishSpeaking: didFinish];
|
||||
NS_HANDLER
|
||||
NS_ENDHANDLER;
|
||||
[args release];
|
||||
[pool release];
|
||||
delete_wave(w);
|
||||
}
|
||||
|
||||
- (void)startSpeaking: (NSString*)aString notifyWhenDone: (id)aDelegate
|
||||
{
|
||||
[[[aDelegate delegate] connectionForProxy] enableMultipleThreads];
|
||||
NSArray *arg = [[NSArray alloc] initWithObjects: aString, aDelegate, nil];
|
||||
shouldEndSpeaking = NO;
|
||||
isSpeaking = YES;
|
||||
[NSThread detachNewThreadSelector: @selector(sayString:)
|
||||
toTarget: self
|
||||
withObject: arg];
|
||||
|
||||
[[[aDelegate delegate] connectionForProxy] enableMultipleThreads];
|
||||
NSArray *arg = [[NSArray alloc] initWithObjects: aString, aDelegate, nil];
|
||||
shouldEndSpeaking = NO;
|
||||
isSpeaking = YES;
|
||||
[NSThread detachNewThreadSelector: @selector(sayString:)
|
||||
toTarget: self
|
||||
withObject: arg];
|
||||
|
||||
}
|
||||
|
||||
- (BOOL)isSpeaking
|
||||
{
|
||||
return isSpeaking;
|
||||
return isSpeaking;
|
||||
}
|
||||
|
||||
- (void)stopSpeaking
|
||||
{
|
||||
shouldEndSpeaking = YES;
|
||||
// Spin until the other thread has died.
|
||||
while (isSpeaking) {}
|
||||
shouldEndSpeaking = YES;
|
||||
// Spin until the other thread has died.
|
||||
while (isSpeaking) {}
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
[self stopSpeaking];
|
||||
audio_close(ad);
|
||||
[super dealloc];
|
||||
[self stopSpeaking];
|
||||
audio_close(ad);
|
||||
[super dealloc];
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation GSSpeechEngine (Flite)
|
||||
+ (GSSpeechEngine*)defaultSpeechEngine
|
||||
{
|
||||
return [[[FliteSpeechEngine alloc] init] autorelease];
|
||||
return [[[FliteSpeechEngine alloc] init] autorelease];
|
||||
}
|
||||
@end
|
||||
|
|
78
configure
vendored
78
configure
vendored
|
@ -635,6 +635,7 @@ GSCUPS_LIBS
|
|||
GSCUPS_LDFLAGS
|
||||
GSCUPS_CFLAGS
|
||||
have_cups
|
||||
BUILD_SPEECH_RECOGNIZER
|
||||
BUILD_SPEECH
|
||||
BUILD_SOUND
|
||||
HAVE_ICU
|
||||
|
@ -729,6 +730,7 @@ with_icu_library
|
|||
enable_aspell
|
||||
enable_sound
|
||||
enable_speech
|
||||
enable_speech_recognizer
|
||||
enable_cups
|
||||
'
|
||||
ac_precious_vars='build_alias
|
||||
|
@ -1384,6 +1386,7 @@ Optional Features:
|
|||
--disable-aspell Disable aspell for spellchecker
|
||||
--disable-sound Disable sound
|
||||
--disable-speech Disable speech server
|
||||
--disable-speech-recognizer Disable speech recognition server
|
||||
--disable-cups Disable cups printing support
|
||||
|
||||
Optional Packages:
|
||||
|
@ -5662,6 +5665,81 @@ fi
|
|||
fi
|
||||
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# NSSpeechRecognizer
|
||||
#--------------------------------------------------------------------
|
||||
# Check whether --enable-speech-recognizer was given.
|
||||
if test "${enable_speech_recognizer+set}" = set; then :
|
||||
enableval=$enable_speech_recognizer;
|
||||
else
|
||||
enable_speech_recognizer=yes
|
||||
fi
|
||||
|
||||
BUILD_SPEECH_RECOGNIZER=
|
||||
|
||||
# has flite, for speech synthesis.
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: checking for ps_start_utt in -lpocketsphinx" >&5
|
||||
$as_echo_n "checking for ps_start_utt in -lpocketsphinx... " >&6; }
|
||||
if ${ac_cv_lib_pocketsphinx_ps_start_utt+:} false; then :
|
||||
$as_echo_n "(cached) " >&6
|
||||
else
|
||||
ac_check_lib_save_LIBS=$LIBS
|
||||
LIBS="-lpocketsphinx $LIBS"
|
||||
cat confdefs.h - <<_ACEOF >conftest.$ac_ext
|
||||
/* end confdefs.h. */
|
||||
|
||||
/* Override any GCC internal prototype to avoid an error.
|
||||
Use char because int might match the return type of a GCC
|
||||
builtin and then its argument prototype would still apply. */
|
||||
#ifdef __cplusplus
|
||||
extern "C"
|
||||
#endif
|
||||
char ps_start_utt ();
|
||||
int
|
||||
main ()
|
||||
{
|
||||
return ps_start_utt ();
|
||||
;
|
||||
return 0;
|
||||
}
|
||||
_ACEOF
|
||||
if ac_fn_c_try_link "$LINENO"; then :
|
||||
ac_cv_lib_pocketsphinx_ps_start_utt=yes
|
||||
else
|
||||
ac_cv_lib_pocketsphinx_ps_start_utt=no
|
||||
fi
|
||||
rm -f core conftest.err conftest.$ac_objext \
|
||||
conftest$ac_exeext conftest.$ac_ext
|
||||
LIBS=$ac_check_lib_save_LIBS
|
||||
fi
|
||||
{ $as_echo "$as_me:${as_lineno-$LINENO}: result: $ac_cv_lib_pocketsphinx_ps_start_utt" >&5
|
||||
$as_echo "$ac_cv_lib_pocketsphinx_ps_start_utt" >&6; }
|
||||
if test "x$ac_cv_lib_pocketsphinx_ps_start_utt" = xyes; then :
|
||||
have_speech_recognizer=yes
|
||||
else
|
||||
have_speech_recognizer=no
|
||||
fi
|
||||
|
||||
for ac_header in pocketsphinx/pocketsphinx.h
|
||||
do :
|
||||
ac_fn_c_check_header_mongrel "$LINENO" "pocketsphinx/pocketsphinx.h" "ac_cv_header_pocketsphinx_pocketsphinx_h" "$ac_includes_default"
|
||||
if test "x$ac_cv_header_pocketsphinx_pocketsphinx_h" = xyes; then :
|
||||
cat >>confdefs.h <<_ACEOF
|
||||
#define HAVE_POCKETSPHINX_POCKETSPHINX_H 1
|
||||
_ACEOF
|
||||
have_pocketsphinx=yes
|
||||
else
|
||||
have_pocketsphinx=no
|
||||
fi
|
||||
|
||||
done
|
||||
|
||||
if test $have_pocketsphinx = yes -a $have_speech_recognizer = yes -a $enable_speech_recognizer = yes; then
|
||||
BUILD_SPEECH_RECOGNIZER="speech_recognizer"
|
||||
POCKETSPHINX_BASE_LIBS="-lpocketsphinx"
|
||||
fi
|
||||
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Find CUPS
|
||||
#--------------------------------------------------------------------
|
||||
|
|
17
configure.ac
17
configure.ac
|
@ -538,6 +538,23 @@ if test $have_flite = yes -a $have_speech = yes -a $enable_speech = yes; then
|
|||
fi
|
||||
AC_SUBST(BUILD_SPEECH)
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# NSSpeechRecognizer
|
||||
#--------------------------------------------------------------------
|
||||
AC_ARG_ENABLE(speech-recognizer,
|
||||
[ --disable-speech-recognizer Disable speech recognition server],,
|
||||
enable_speech_recognizer=yes)
|
||||
BUILD_SPEECH_RECOGNIZER=
|
||||
|
||||
# has flite, for speech synthesis.
|
||||
AC_CHECK_LIB(pocketsphinx, ps_start_utt, have_speech_recognizer=yes, have_speech_recognizer=no)
|
||||
AC_CHECK_HEADERS(pocketsphinx/pocketsphinx.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"
|
||||
POCKETSPHINX_BASE_LIBS="-lpocketsphinx"
|
||||
fi
|
||||
AC_SUBST(BUILD_SPEECH_RECOGNIZER)
|
||||
|
||||
#--------------------------------------------------------------------
|
||||
# Find CUPS
|
||||
#--------------------------------------------------------------------
|
||||
|
|
Loading…
Reference in a new issue