- This topic has 7 replies, 2 voices, and was last updated 9 years, 4 months ago by Halle Winkler.
-
AuthorPosts
-
December 2, 2014 at 7:02 pm #1023135salhayekParticipant
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!
December 2, 2014 at 7:33 pm #1023136Halle WinklerPolitepixWelcome,
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.
December 2, 2014 at 7:51 pm #1023137salhayekParticipantThank 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.
December 2, 2014 at 7:58 pm #1023138Halle WinklerPolitepixThat’s correct, each language model requires a unique name.
December 2, 2014 at 8:03 pm #1023139salhayekParticipantFor 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?
December 2, 2014 at 8:18 pm #1023140Halle WinklerPolitepixFor 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.
December 2, 2014 at 8:45 pm #1023141salhayekParticipantThank you so much! You really helped me out! :)
December 2, 2014 at 9:00 pm #1023142Halle WinklerPolitepixYou’re welcome!
-
AuthorPosts
- You must be logged in to reply to this topic.