Change vocabulary array on the fly?

Home Forums OpenEars Change vocabulary array on the fly?

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

  • Author
    Posts
  • #1019412
    davestrand
    Participant

    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.

    #1019414
    davestrand
    Participant

    Here’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.
            
        }
        
    }
    #1019415
    Halle Winkler
    Politepix

    Welcome,

    A current limitation is that language models need to have unique names. Does it work better if you use a different name every time?

    #1019417
    davestrand
    Participant

    Hm. I’ll give that a shot and see what happens, thanks!

    #1019418
    davestrand
    Participant

    Hm.. 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.

    #1019419
    Halle Winkler
    Politepix

    The requested name under withFilesNamed: when they are being regenerated.

    #1019420
    davestrand
    Participant

    Sorry 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.

    #1019421
    Halle Winkler
    Politepix

    OK, no worries — let me know if you get it working or if you have a follow-up question.

    #1019422
    davestrand
    Participant

    So, 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.

    #1019423
    Halle Winkler
    Politepix

    I 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: ?

    #1019424
    davestrand
    Participant

    Sure 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;`

    #1019425
    Halle Winkler
    Politepix

    OK, 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?

    #1019426
    davestrand
    Participant

    Yeah, ‘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];

    #1019428
    davestrand
    Participant

    Sorry, 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;
        
        
       
    
        
    
        
       
    }
    #1019429
    Halle Winkler
    Politepix

    I 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.

    #1019431
    davestrand
    Participant

    Of course, you are right. :) I will work through the sample app and streamline my app.
    Thank you for your time.

    #1019437
    davestrand
    Participant

    One 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?

    #1019444
    Halle Winkler
    Politepix

    I 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.

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