[Resolved] Wondering how to add words to be recognized in app

Home Forums OpenEars [Resolved] Wondering how to add words to be recognized in app

Viewing 8 posts - 1 through 8 (of 8 total)

  • Author
    Posts
  • #1023135
    salhayek
    Participant

    I am trying to put together a project for school where a user can be prompted to add words that will later be recognized in the app when spoken. I was able to get the word added but the only way it would be processed is if the app was restarted. I was wondering how to get the word list reprocessed as soon as the user hits submit in the app.

    I have been searching for a while and haven’t found anything that could help me and thought I would post a question. Thanks so much for all the help!

    #1023136
    Halle Winkler
    Politepix

    Welcome,

    You just need to generate a new language model (in the same way you generated your initial model) and then call PocketsphinxController’s method:

    - (void) changeLanguageModelToFile:(NSString *)languageModelPathAsString withDictionary:(NSString *)dictionaryPathAsString;
    

    On an already-running listening session. This will switch over to your new model without any delay.

    #1023137
    salhayek
    Participant

    Thank you so much it turns out I just wasn’t calling that method.

    When the user hits submit:

    NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
                [defaults setObject:alertTextInput forKey:@"commandword"];
                [self loadAppSettings];
                
                NSLog(@"The new command is %@", self.commandWord);
                
                [self LanguageGenerator];
                [pocketsphinxController changeLanguageModelToFile:self.lmPath withDictionary:self.dicPath];

    In the language generator method:

    LanguageModelGenerator *lmGenerator = [[LanguageModelGenerator alloc] init];
        
        self.wordList = [NSArray arrayWithObjects:
                            self.commandWord,
                            nil];
        
        NSError *err = [lmGenerator generateLanguageModelFromArray:self.wordList withFilesNamed:@"LanguageModelFile" forAcousticModelAtPath:[AcousticModel pathToModel:@"AcousticModelEnglish"]];
        
        
        self.languageGeneratorResults = nil;
        self.lmPath = nil;
        self.dicPath = nil;
        
        if([err code] == noErr) {
            
            self.languageGeneratorResults = [err userInfo];
            
            self.lmPath = [self.languageGeneratorResults objectForKey:@"LMPath"];
            self.dicPath = [self.languageGeneratorResults objectForKey:@"DictionaryPath"];
            
        } else {
            NSLog(@"Error: %@",[err localizedDescription]);
        }
    }
    

    So it works now but only the first time I do it. If I try to go and change it again, it won’t recognize the word. I was reading somewhere on the forums that the names of the paths have to be unique, does this apply here?

    Thanks again for the help, you are definitely a life saver.

    #1023138
    Halle Winkler
    Politepix

    That’s correct, each language model requires a unique name.

    #1023139
    salhayek
    Participant

    For the unique names, we are talking about the self.lmPath and self.dicPath in regards to the code above right?

    If users were going to change it multiple times in one sitting, should I generate a random string to name the files? If so, I think it would eventually take up space on the device. Or is there a way to clear the files created?

    #1023140
    Halle Winkler
    Politepix

    For the unique names, we are talking about the self.lmPath and self.dicPath in regards to the code above right?

    We’re talking about the value given to withFilesNamed: above.

    If users were going to change it multiple times in one sitting, should I generate a random string to name the files? If so, I think it would eventually take up space on the device. Or is there a way to clear the files created?

    Once you have stopped listening (not while listening is in progress) you can delete them as you would any other file system files you have permissions to delete.

    #1023141
    salhayek
    Participant

    Thank you so much! You really helped me out! :)

    #1023142
    Halle Winkler
    Politepix

    You’re welcome!

Viewing 8 posts - 1 through 8 (of 8 total)
  • You must be logged in to reply to this topic.