Cleanup. Fix issues pointed out in review.

This commit is contained in:
Gregory John Casamento 2020-02-07 04:50:40 -05:00
parent f823bf3021
commit 3468a92539
3 changed files with 27 additions and 17 deletions

View file

@ -47,20 +47,23 @@ BOOL _serverLaunchTested = NO;
+ (void) initialize
{
_speechRecognitionServer = [NSConnection
rootProxyForConnectionWithRegisteredName: SPEECH_RECOGNITION_SERVER
host: nil];
RETAIN(_speechRecognitionServer);
if (nil == _speechRecognitionServer)
if (self == [NSSpeechRecognizer class])
{
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
[ws launchApplication: SPEECH_RECOGNITION_SERVER
showIcon: NO
autolaunch: NO];
}
else
{
NSLog(@"Server found in +initialize");
_speechRecognitionServer = [NSConnection
rootProxyForConnectionWithRegisteredName: SPEECH_RECOGNITION_SERVER
host: nil];
RETAIN(_speechRecognitionServer);
if (nil == _speechRecognitionServer)
{
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
[ws launchApplication: SPEECH_RECOGNITION_SERVER
showIcon: NO
autolaunch: NO];
}
else
{
NSLog(@"Server found in +initialize");
}
}
}

View file

@ -34,13 +34,16 @@ static int clients;
@implementation GSSpeechRecognizer
+ (void)initialize
{
server = [GSSpeechRecognitionServer sharedServer];
RETAIN(server);
[[NSNotificationCenter defaultCenter]
if (self == [GSSpeechRecognizer class])
{
server = [GSSpeechRecognitionServer sharedServer];
RETAIN(server);
[[NSNotificationCenter defaultCenter]
addObserver: self
selector: @selector(connectionDied:)
name: NSConnectionDidDieNotification
object: nil];
}
}
/**

View file

@ -53,7 +53,7 @@ static const arg_t cont_args_def[] = {
"Audio file to transcribe."},
{"-inmic",
ARG_BOOLEAN,
"no",
"yes",
"Transcribe audio from microphone."},
{"-time",
ARG_BOOLEAN,
@ -133,16 +133,19 @@ static const arg_t cont_args_def[] = {
"-samprate"))) == NULL)
{
NSLog(@"Failed to open audio device");
return;
}
if (ad_start_rec(ad) < 0)
{
NSLog(@"Failed to start recording");
return;
}
if (ps_start_utt(ps) < 0)
{
NSLog(@"Failed to start utterance");
return;
}
utt_started = NO;
@ -153,6 +156,7 @@ static const arg_t cont_args_def[] = {
if ((k = ad_read(ad, adbuf, 2048)) < 0)
{
NSLog(@"Failed to read audio");
break;
}
ps_process_raw(ps, adbuf, k, FALSE, FALSE);