Home › Forums › OpenEars › Problem when using NSDictionary › Reply To: Problem when using NSDictionary
oops!
Heres my .m file again
#import “ViewController.h”
#import <OpenEars/OELanguageModelGenerator.h>
#import <OpenEars/OEPocketsphinxController.h>
#import <OpenEars/OEAcousticModel.h>
@interface ViewController ()
@end
@implementation ViewController
– (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
OELanguageModelGenerator *lmGenerator = [[OELanguageModelGenerator alloc] init];
//NSArray *words = [NSArray arrayWithObjects: @”1″, @”2″, @”3″, @”4″, @”5″, @”6″, nil];
NSDictionary *grammar = @{
ThisWillBeSaidOnce : @[
@{ OneOfTheseCanBeSaidOnce : @[@”HELLO COMPUTER”, @”GREETINGS ROBOT”]},
@{ OneOfTheseWillBeSaidOnce : @[@”DO THE FOLLOWING”, @”INSTRUCTION”]},
@{ OneOfTheseWillBeSaidOnce : @[@”GO”, @”MOVE”]},
@{ThisWillBeSaidOnce : @[
@{ OneOfTheseWillBeSaidOnce : @[@”10″, @”20″,@”30″]},
@{ OneOfTheseWillBeSaidOnce : @[@”LEFT”, @”RIGHT”, @”FORWARD”]}
]},
@{ ThisCanBeSaidOnce : @[@”THANK YOU”]}
]
};
NSString *name = @”MyLanguageModelFiles”;
NSError *err = [lmGenerator generateGrammarFromDictionary:grammar withFilesNamed:name forAcousticModelAtPath:[OEAcousticModel pathToModel:@”AcousticModelEnglish”]];
NSString *lmPath = nil;
NSString *dicPath = nil;
if(err == nil) {
lmPath = [lmGenerator pathToSuccessfullyGeneratedLanguageModelWithRequestedName:@”MyLanguageModelFiles”];
dicPath = [lmGenerator pathToSuccessfullyGeneratedDictionaryWithRequestedName:@”MyLanguageModelFiles”];
} else {
NSLog(@”Error: %@”,[err localizedDescription]);
}
[[OEPocketsphinxController sharedInstance] setActive:TRUE error:nil];
[[OEPocketsphinxController sharedInstance] startListeningWithLanguageModelAtPath:lmPath dictionaryAtPath:dicPath acousticModelAtPath:[OEAcousticModel pathToModel:@”AcousticModelEnglish”] languageModelIsJSGF:NO];
self.openEarsEventsObserver = [[OEEventsObserver alloc] init];
[self.openEarsEventsObserver setDelegate:self];
self.fliteController = [[OEFliteController alloc] init];
self.slt = [[Slt alloc] init];
self.openEarsEventsObserver = [[OEEventsObserver alloc] init];
[self.openEarsEventsObserver setDelegate:self];
}
– (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
– (void) pocketsphinxDidReceiveHypothesis:(NSString *)hypothesis recognitionScore:(NSString *)recognitionScore utteranceID:(NSString *)utteranceID {
NSLog(@”The received hypothesis is %@ with a score of %@ and an ID of %@”, hypothesis, recognitionScore, utteranceID);
self.wordSpoken.text = hypothesis;
[self.fliteController say:hypothesis withVoice:self.slt];
}
– (void) pocketsphinxDidStartListening {
NSLog(@”Pocketsphinx is now listening.”);
}
– (void) pocketsphinxDidDetectSpeech {
NSLog(@”Pocketsphinx has detected speech.”);
}
– (void) pocketsphinxDidDetectFinishedSpeech {
NSLog(@”Pocketsphinx has detected a period of silence, concluding an utterance.”);
}
– (void) pocketsphinxDidStopListening {
NSLog(@”Pocketsphinx has stopped listening.”);
}
– (void) pocketsphinxDidSuspendRecognition {
NSLog(@”Pocketsphinx has suspended recognition.”);
}
– (void) pocketsphinxDidResumeRecognition {
NSLog(@”Pocketsphinx has resumed recognition.”);
}
– (void) pocketsphinxDidChangeLanguageModelToFile:(NSString *)newLanguageModelPathAsString andDictionary:(NSString *)newDictionaryPathAsString {
NSLog(@”Pocketsphinx is now using the following language model: \n%@ and the following dictionary: %@”,newLanguageModelPathAsString,newDictionaryPathAsString);
}
– (void) pocketSphinxContinuousSetupDidFailWithReason:(NSString *)reasonForFailure {
NSLog(@”Listening setup wasn’t successful and returned the failure reason: %@”, reasonForFailure);
}
– (void) pocketSphinxContinuousTeardownDidFailWithReason:(NSString *)reasonForFailure {
NSLog(@”Listening teardown wasn’t successful and returned the failure reason: %@”, reasonForFailure);
}
– (void) testRecognitionCompleted {
NSLog(@”A test file that was submitted for recognition is now complete.”);
}