Tagged: change, model, real, time, vocabulary
- This topic has 17 replies, 2 voices, and was last updated 10 years, 3 months ago by Halle Winkler.
-
AuthorPosts
-
January 13, 2014 at 6:49 pm #1019412davestrandParticipant
I would like to change the recognized vocabulary (Model, Array) real-time based on dictionaries in the plist. I have gotten it so that it loads a few words from the appropriate dictionary at startup, as well as some others I have manually entered into the array, but I am not sure how to RE-load the recognized vocabulary once the app is running. I have created a function, and logged it to be sure that my new variables are there… I pasted what I believe to be the appropriate setup code inside a special reLoadLanguageBasedOnNewVariables function, including the startup array of words, however it doesn’t actually RE-load the understood dictionary when i call upon that function. I’m probably missing something, as I’m new to objective c. My design is based off of a heavily modified version of the “Change Model” style example… which might be part of my problem. If you could help that would be great. I have gone through the tutorial, but must be missing something.
January 13, 2014 at 6:55 pm #1019414davestrandParticipantHere’s the function to attempt to reload based on plist data..
- (void) reLoadLanguageBasedOnNewVariables { LanguageModelGenerator *languageModelGenerator = [[LanguageModelGenerator alloc] init]; NSArray *languageArray = [[NSArray alloc] initWithArray:[NSArray arrayWithObjects: // All capital letters. @"YES", @"NO", @"MAYBE", @"DIAPER", @"%@",[NSString stringWithFormat:@"%@", [playerIsNowAt valueForKey:@"ObjectsInLocation"]], nil]]; NSLog(@"Checking the objects in the room are correct %@", [playerIsNowAt valueForKey:@"ObjectsInLocation"]);//Yep, it's loading the new objects NSString *name = @"VoiceGameModelFiles"; NSError *err = [languageModelGenerator generateLanguageModelFromArray:languageArray withFilesNamed:name forAcousticModelAtPath:[AcousticModel pathToModel:@"AcousticModelEnglish"]]; // Change "AcousticModelEnglish" to "AcousticModelSpanish" to create a Spanish language model instead of an English one. NSDictionary *dynamicLanguageGenerationResultsDictionary = nil; if([err code] != noErr) { NSLog(@"Dynamic language generator reported error %@", [err description]); } else { dynamicLanguageGenerationResultsDictionary = [err userInfo]; NSString *lmPath = [dynamicLanguageGenerationResultsDictionary objectForKey:@"LMPath"]; NSString *dictionaryPath = [dynamicLanguageGenerationResultsDictionary objectForKey:@"DictionaryPath"]; self.pathToDynamicallyGeneratedGrammar = lmPath; // We'll set our new .languagemodel file to be the one to get switched to when the words "CHANGE MODEL" are recognized. self.pathToDynamicallyGeneratedDictionary = dictionaryPath; // We'll set our new dictionary to be the one to get switched to when the words "CHANGE MODEL" are recognized. } }
January 13, 2014 at 6:55 pm #1019415Halle WinklerPolitepixWelcome,
A current limitation is that language models need to have unique names. Does it work better if you use a different name every time?
January 13, 2014 at 6:56 pm #1019417davestrandParticipantHm. I’ll give that a shot and see what happens, thanks!
January 13, 2014 at 7:12 pm #1019418davestrandParticipantHm.. I am not noticing any difference if I change the name.. Are you referring to the LanguageModelGenerator *languageModelGenerator and the NSArray *languageArray names? I tried changing those as well as many of the other *names, and the NSString *name = @”VoiceGameModelFiles1 <– “; Figured they might at least work once, if the name needs to rotate.
January 13, 2014 at 7:20 pm #1019419Halle WinklerPolitepixThe requested name under withFilesNamed: when they are being regenerated.
January 13, 2014 at 7:26 pm #1019420davestrandParticipantSorry to keep posting.. it looks like my tests might have been inconclusive. Looks like I call the function once when the app starts, so the filename wasn’t a new one. I’m not entirely sure how to rotate and then call upon a filename.. Trying to learn up on that now.
January 13, 2014 at 7:33 pm #1019421Halle WinklerPolitepixOK, no worries — let me know if you get it working or if you have a follow-up question.
January 13, 2014 at 9:14 pm #1019422davestrandParticipantSo, I did get a random name generating.. I was able to confirm it’s functionality because I located the Cache folder and saw the three files being created… When I opened the .dic file I saw the appropriate Words. I think I’m still missing a piece of code that loads this new dictionary into use and turns it on. I posted my code in the thread above. Do you see anything terribly wrong or missing? Something special must happen at the viewDidLoad, because it starts up ok, but then never changes.
January 13, 2014 at 9:26 pm #1019423Halle WinklerPolitepixI only see the code for generating the models above, but not starting with the language model or changing it in an already-started listening session. Do you want to show me that code which uses startListeningWithLanguageModelAtPath: etc and changeLanguageModelToFile: ?
January 13, 2014 at 9:43 pm #1019424davestrandParticipantSure thing.. thank you SOO much for taking the time.
- (void) startListening { [self.pocketsphinxController startListeningWithLanguageModelAtPath:self.pathToGrammarToStartAppWith dictionaryAtPath:self.pathToDictionaryToStartAppWith acousticModelAtPath:[AcousticModel pathToModel:@"AcousticModelEnglish"] languageModelIsJSGF:FALSE]; }
and in viewDidLoad..
[self startListening];
` [self.pocketsphinxController changeLanguageModelToFile:self.pathToDynamicallyGeneratedGrammar withDictionary:self.pathToDynamicallyGeneratedDictionary]; //I’M FORCING IT into our VoiceGameCorpus.txt.. eventually simplify startup language, or learn how to switch based on city/location.
self.usingStartLanguageModel = FALSE;`January 13, 2014 at 9:47 pm #1019425Halle WinklerPolitepixOK, that shows starting up with one model but the switching is immediately after the startup, so that might be your issue. How are you switching when it’s time to switch, and where in your code?
January 13, 2014 at 11:01 pm #1019426davestrandParticipantYeah, ‘busted’.. I was being lazy and couldn’t suss out how to keep all the other functionality of your “Change Model” example, so I forced it to “Change Model” early on. I don’t think it ever changes back after that first change command.
I’ll buckle down and try and streamline the integration by defaulting to the correct vocabulary. It’s a bit (lot) over my head, but I like to learn.
The last bit of code that may pertain is located in pocketsphinxDidReceiveHypothesis… which among other things has this inside.
[self reLoadLanguageBasedOnNewVariables];
January 13, 2014 at 11:08 pm #1019428davestrandParticipantSorry, here’s from the initial setup..
//[OpenEarsLogging startOpenEarsLogging]; // Uncomment me for OpenEarsLogging [self.openEarsEventsObserver setDelegate:self]; // This is the language model we're going to start up with. #pragma mark STARTING LANGUAGE self.pathToGrammarToStartAppWith = [NSString stringWithFormat:@"%@/%@",[[NSBundle mainBundle] resourcePath], @"OpenEars1.languagemodel"]; self.pathToDictionaryToStartAppWith = [NSString stringWithFormat:@"%@/%@",[[NSBundle mainBundle] resourcePath], @"OpenEars1.dic"]; self.usingStartLanguageModel = TRUE; #pragma mark CUSTOM LANGUAGE [self reLoadLanguageBasedOnNewVariables]; //----DL ADDED TO TRY AND PULL LOCATION INFO FROM FUNCTION [self startListening]; //--- DL ADDED THIS FROM ABOVE [self startDisplayingLevels]; // Here is some UI stuff that has nothing specifically to do with OpenEars implementation self.startButton.hidden = TRUE; self.stopButton.hidden = TRUE; self.suspendListeningButton.hidden = TRUE; self.resumeListeningButton.hidden = TRUE; //DL EXPERIMENTS BELOW// [self.pocketsphinxController changeLanguageModelToFile:self.pathToDynamicallyGeneratedGrammar withDictionary:self.pathToDynamicallyGeneratedDictionary]; //I'M FORCING IT into our VoiceGameCorpus.txt.. eventually simplify startup language, or learn how to switch based on city/location. self.usingStartLanguageModel = FALSE; }
January 13, 2014 at 11:09 pm #1019429Halle WinklerPolitepixI think maybe it isn’t that rewarding to change the model right after starting the listening loop, since you could just start it with the model you want. Probably the issue is that you have to decide on what event you want to change the model and then take a look at the specific model changing code in the sample app in order to see how it is implemented.
January 14, 2014 at 12:19 am #1019431davestrandParticipantOf course, you are right. :) I will work through the sample app and streamline my app.
Thank you for your time.January 14, 2014 at 2:21 am #1019437davestrandParticipantOne last question.. once it’s up and running, based on the need to create random file names, won’t that be generating a lot of .dic and associated files? Do you think it necessary that I programmatically remove those files and clear the cache?
January 14, 2014 at 12:01 pm #1019444Halle WinklerPolitepixI think it is probably going to work fine without the multiple file names once you are using changeLanguageModelToFile: in line with its design. Keep in mind that changeLanguageModelToFile: gets used on already-started listening loop, so don’t stop and start the listening loop in order to change models, just send the change message as a result of whatever the change event is and it will change, just like it works in the sample app. Something that might be a bit of a red herring for you with the sample app is that it has a startListening method, but this only part of the design of the sample app so that I can demonstrate how to recover from a route change or phone call interruption. The way to start listening is by using – (void) startListeningWithLanguageModelAtPath:dictionaryAtPath:acousticModelAtPath:languageModelIsJSGF: and the tutorial is probably a better way to get an understanding of how those calls should be invoked, with the sample app only used for confirming how changing models on the fly works.
-
AuthorPosts
- You must be logged in to reply to this topic.