diff --git a/src/Hear.h b/src/Hear.h index 0a9dc0c..c28c8f4 100644 --- a/src/Hear.h +++ b/src/Hear.h @@ -38,7 +38,7 @@ + (void)printSupportedLanguages; -- (instancetype)initWithLanguage:(NSString *)language +- (instancetype)initWithLocale:(NSString *)language input:(NSString *)input onDevice:(BOOL)useOnDeviceRecognition singleLineMode:(BOOL)singleLine diff --git a/src/Hear.m b/src/Hear.m index efde9ae..cc5edf4 100644 --- a/src/Hear.m +++ b/src/Hear.m @@ -41,7 +41,7 @@ @interface Hear() @property (nonatomic, retain) AVAudioEngine *engine; -@property (nonatomic, retain) NSString *language; +@property (nonatomic, retain) NSString *locale; @property (nonatomic, retain) NSString *inputFile; @property (nonatomic) BOOL useDeviceInput; @property (nonatomic) BOOL useOnDeviceRecognition; @@ -53,21 +53,21 @@ @interface Hear() @implementation Hear -- (instancetype)initWithLanguage:(NSString *)language - input:(NSString *)input - onDevice:(BOOL)onDevice - singleLineMode:(BOOL)singleLine - addPunctuation:(BOOL)punctuation - exitWord:(NSString *)exitWord { +- (instancetype)initWithLocale:(NSString *)loc + input:(NSString *)input + onDevice:(BOOL)onDevice + singleLineMode:(BOOL)singleLine + addPunctuation:(BOOL)punctuation + exitWord:(NSString *)exitWord { self = [super init]; if (self) { - if ([[Hear supportedLanguages] containsObject:language] == NO) { - NSPrintErr(@"Locale '%@' not supported. Run with -s flag to see list of supported locales", language); + if ([[Hear supportedLanguages] containsObject:loc] == NO) { + NSPrintErr(@"Locale '%@' not supported. Run with -s flag to see list of supported locales", loc); exit(EXIT_FAILURE); } - self.language = language; + self.locale = loc; self.inputFile = input; self.useOnDeviceRecognition = onDevice; self.singleLineMode = singleLine; @@ -87,8 +87,7 @@ - (void)applicationDidFinishLaunching:(NSNotification *)notification { #pragma mark - - (void)die:(NSString *)errMsg { - NSString *msg = [NSString stringWithFormat:@"Error: %@", errMsg]; - NSPrintErr(msg); + NSPrintErr(@"Error: %@", errMsg); exit(EXIT_FAILURE); } @@ -124,7 +123,7 @@ - (void)requestSpeechRecognitionPermission { - (void)initRecognizer { // Initialize speech recognizer - NSLocale *locale = [NSLocale localeWithLocaleIdentifier:self.language]; + NSLocale *locale = [NSLocale localeWithLocaleIdentifier:self.locale]; self.recognizer = [[SFSpeechRecognizer alloc] initWithLocale:locale]; if (self.recognizer == nil) { [self die:@"Unable to initialize speech recognizer"]; @@ -137,7 +136,7 @@ - (void)initRecognizer { } if (self.useOnDeviceRecognition && !self.recognizer.supportsOnDeviceRecognition) { - [self die:[NSString stringWithFormat:@"On-device recognition is not supported for locale '%@'", self.language]]; + [self die:[NSString stringWithFormat:@"On-device recognition is not supported for locale '%@'", self.locale]]; } } diff --git a/src/main.m b/src/main.m index 52efb6a..1f6ae38 100644 --- a/src/main.m +++ b/src/main.m @@ -76,7 +76,7 @@ int main(int argc, const char * argv[]) { @autoreleasepool { exit(EXIT_FAILURE); } - NSString *language = DEFAULT_LOCALE; + NSString *locale = DEFAULT_LOCALE; NSString *inputFilename; NSString *exitWord; BOOL useOnDeviceRecognition = NO; @@ -98,7 +98,7 @@ int main(int argc, const char * argv[]) { @autoreleasepool { // Set language (i.e. locale) for speech recognition case 'l': - language = @(optarg); + locale = @(optarg); break; // Input filename (path) @@ -143,12 +143,12 @@ int main(int argc, const char * argv[]) { @autoreleasepool { } // Instantiate app delegate object with core program functionality - Hear *hear = [[Hear alloc] initWithLanguage:language - input:inputFilename - onDevice:useOnDeviceRecognition - singleLineMode:singleLineMode - addPunctuation:addsPunctuation - exitWord:exitWord]; + Hear *hear = [[Hear alloc] initWithLocale:locale + input:inputFilename + onDevice:useOnDeviceRecognition + singleLineMode:singleLineMode + addPunctuation:addsPunctuation + exitWord:exitWord]; [[NSApplication sharedApplication] setDelegate:hear]; [[NSApplication sharedApplication] run];