geofftowell

Forum Replies Created

Viewing 1 post (of 1 total)

  • Author
    Posts
  • in reply to: problems using generateGrammarFromDictionary #1022085
    geofftowell
    Participant

    Overnight I got to thinking and read through the documentation several more times. With some more experimentation, I got recognition with grammars working in the sample code by modifying the viewDidLoad and startListening methods as shown below. (I removed a bunch of comments to make things shorter.)

    The central thing I had missed was changing languageModelIsJSGF to TRUE in the startListeningWithLanguageModelAtPath method

    Thanks for your help.

    – (void) startListening {

    self.pocketsphinxController.returnNullHypotheses=YES;
    self.pocketsphinxController.verbosePocketSphinx=YES;
    [self.pocketsphinxController startListeningWithLanguageModelAtPath:self.pathToFirstDynamicallyGeneratedLanguageModel dictionaryAtPath:self.pathToFirstDynamicallyGeneratedDictionary acousticModelAtPath:[AcousticModel pathToModel:@”AcousticModelEnglish”] languageModelIsJSGF:TRUE]; // Change “AcousticModelEnglish” to “AcousticModelSpanish” in order to perform Spanish recognition instead of English.
    self.pocketsphinxController.verbosePocketSphinx=YES;

    }

    – (void)viewDidLoad {
    [super viewDidLoad];
    [OpenEarsLogging startOpenEarsLogging];
    self.restartAttemptsDueToPermissionRequests = 0;
    self.startupFailedDueToLackOfPermissions = FALSE;

    [self.openEarsEventsObserver setDelegate:self];
    LanguageModelGenerator *languageModelGenerator = [[LanguageModelGenerator alloc] init];
    NSDictionary *dd = @{
    ThisWillBeSaidOnce : @[
    @{ OneOfTheseCanBeSaidOnce : @[@”HELLO COMPUTER”, @”GREETINGS ROBOT”]},
    @{ OneOfTheseWillBeSaidOnce : @[@”GO”, @”MOVE”]},
    @{ OneOfTheseWillBeSaidOnce : @[@”EXECUTE”, @”DO IT”]},
    ]
    };
    NSError *error2 = [languageModelGenerator generateGrammarFromDictionary:dd withFilesNamed:@”FirstOpenEarsDynamicLanguageModelG” forAcousticModelAtPath:[AcousticModel pathToModel:@”AcousticModelEnglish”]];

    NSDictionary *firstDynamicLanguageGenerationResultsDictionary = nil;
    if([error2 code] != noErr) {
    NSLog(@”Dynamic language generator reported error %@”, [error2 description]);
    } else {
    firstDynamicLanguageGenerationResultsDictionary = [error2 userInfo];

    NSString *lmFile = [firstDynamicLanguageGenerationResultsDictionary objectForKey:@”LMFile”];
    NSString *dictionaryFile = [firstDynamicLanguageGenerationResultsDictionary objectForKey:@”DictionaryFile”];
    NSString *lmPath = [firstDynamicLanguageGenerationResultsDictionary objectForKey:@”LMPath”];
    NSString *dictionaryPath = [firstDynamicLanguageGenerationResultsDictionary objectForKey:@”DictionaryPath”];

    NSLog(@”Dynamic language generator completed successfully, you can find your new files %@\n and \n%@\n at the paths \n%@ \nand \n%@”, lmFile,dictionaryFile,lmPath,dictionaryPath);

    self.pathToFirstDynamicallyGeneratedLanguageModel = lmPath;
    self.pathToFirstDynamicallyGeneratedDictionary = dictionaryPath;
    }

    self.usingStartLanguageModel = TRUE;
    [self startListening];
    [self startDisplayingLevels];
    self.startButton.hidden = TRUE;
    self.stopButton.hidden = TRUE;
    self.suspendListeningButton.hidden = TRUE;
    self.resumeListeningButton.hidden = TRUE;
    }

Viewing 1 post (of 1 total)