not sure how to use ChangeLanguageModelToFile

Home Forums OpenEars not sure how to use ChangeLanguageModelToFile

Tagged: , ,

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

  • Author
    Posts
  • #1022409
    JonLocate
    Participant

    Hey,

    Im not quite sure how to use this function to change language models. In the tutorial this bit of code sets up the initial language model

    
    NSArray *words = [NSArray arrayWithObjects:@"WORD", @"STATEMENT", @"OTHER WORD", @"A PHRASE", nil];
    NSString *name = @"NameIWantForMyLanguageModelFiles";
    NSError *err = [lmGenerator generateLanguageModelFromArray:words withFilesNamed:name forAcousticModelAtPath:[AcousticModel pathToModel:@"AcousticModelEnglish"]]; // Change "AcousticModelEnglish" to "AcousticModelSpanish" to create a Spanish language model instead of an English one.
    
    NSDictionary *languageGeneratorResults = nil;
    
    NSString *lmPath = nil;
    NSString *dicPath = nil;
    	
    if([err code] == noErr) {
    	
    	languageGeneratorResults = [err userInfo];
    		
    	lmPath = [languageGeneratorResults objectForKey:@"LMPath"];
    	dicPath = [languageGeneratorResults objectForKey:@"DictionaryPath"];
    		
    } else {
    	NSLog(@"Error: %@",[err localizedDescription]);
    }
    
    

    how do i create another model to be used? should i reuse the above code and overwrite the current model with the new array of words to be used and overwrite back to the old array for the first model when i want that?

    or should i create another block of the same code but change var names to get new paths

    a la

    
    
    NSArray *MoreWords = [NSArray arrayWithObjects:@"MORE", @"WORDS", @"OTHER MODEL", @"A PHRASE ONLY BIGGER", nil];
    NSString *NewName = @"NameIWantForMyLanguageModelFiles";
    NSError *newModel = [lmGenerator generateLanguageModelFromArray:MoreWords withFilesNamed:NewName forAcousticModelAtPath:[AcousticModel pathToModel:@"AcousticModelEnglish"]]; // Change "AcousticModelEnglish" to "AcousticModelSpanish" to create a Spanish language model instead of an English one.
    
    NSDictionary *NewLanguageGeneratorResults = nil;
    
    NSString *NewLmPath = nil;
    NSString *NewDicPath = nil;
    	
    if([newModel code] == noErr) {
    	
    	NewlanguageGeneratorResults = [newModel userInfo];
    		
    	NewLmPath = [languageGeneratorResults objectForKey:@"LMPath"];
    	NewDicPath = [languageGeneratorResults objectForKey:@"DictionaryPath"];
    		
    } else {
    	NSLog(@"Error: %@",[err localizedDescription]);
    }
    
    

    and then called the change method like

    
    [pocketSphinxXontroller changeLanguageModelToFile:NewLmPath withDictionary:NewDicPath];
    
    

    Thanks for the help!

    #1022410
    Halle Winkler
    Politepix

    The sample app has examples for creating new models and switching between them.

    #1022411
    JonLocate
    Participant

    After looking through the example i modified my code to have a second language model and its paths

    
    
    NSString *name = @"commandModel";
        
        NSError *commandModel = [lmGenerator generateRejectingLanguageModelFromArray:commandVocab withFilesNamed:name withOptionalExclusions:nil usingVowelsOnly:FALSE withWeight:nil forAcousticModelAtPath:[AcousticModel pathToModel:@"AcousticModelEnglish"]];
        
        NSDictionary *languageGeneratorResults = nil;
        
        if([commandModel code] == noErr)
        {
            languageGeneratorResults = [commandModel userInfo];
    // not sure if i need these file vars as they are not in the tutorial but are in the demo app
            lmFile = [languageGeneratorResults objectForKey:@"LMFile"];
            dicFile = [languageGeneratorResults objectForKey:@"DictionaryFile"];
            lmPath = [languageGeneratorResults objectForKey:@"LMPath"];
            dicPath = [languageGeneratorResults objectForKey:@"DictionaryPath"];
        }
        else
        {
            NSLog(@"Error: %@",[commandModel localizedDescription]);
        }
        
        
        
    
        
        NSString *name1 = @"BreadModel";
        
        NSError *breadModel = [lmGenerator generateRejectingLanguageModelFromArray:breadVocab withFilesNamed:name1 withOptionalExclusions:nil usingVowelsOnly:FALSE withWeight:nil forAcousticModelAtPath:[AcousticModel pathToModel:@"AcousticModelEnglish"]];
        
        NSDictionary *breadlanguageGeneratorResults = nil;
        
        if([breadModel code] == noErr)
        {
            breadlanguageGeneratorResults = [commandModel userInfo];
            breadlmFile = [breadlanguageGeneratorResults objectForKey:@"LMFile"];
            breaddicFile = [breadlanguageGeneratorResults objectForKey:@"DictionaryFile"];
            breadlmPath = [breadlanguageGeneratorResults objectForKey:@"LMPath"];
            breaddicPath = [breadlanguageGeneratorResults objectForKey:@"DictionaryPath"];
        }
        else
        {
            NSLog(@"Error: %@",[breadModel localizedDescription]);
        }
    
    

    then when i want to change the model i call this

    
    
    [pocketsphinxController changeLanguageModelToFile:breadlmPath withDictionary:breaddicPath];
    
    

    not a lot different from the demo app yet the model doesn’t get changed and the model changed delegate method doesn’t get called. any ideas?

    Thanks
    Jon

    #1022412
    Halle Winkler
    Politepix

    Same general troubleshooting advice as before –– compare to the known-working example and change what is different until you’ve isolated your issue.

    Your previous question had the same characteristic of all of the OpenEars objects being referenced by ivar of unknown alloc/init status rather than a known-to-be-instantiated property as shown in the tutorial and sample app. From that question:

    the first step is to turn on verbosePocketsphinx and show me the output

    Please turn on OpenEarsLogging and verbosePocketsphinx for this kind of issue, since there’s no way of knowing what is happening in your app without any logging output and without getting to see any instantiation code for Pocketsphinx or LanguageModelGenerator. You can read more about it in this post entitled “Please read before you post – how to troubleshoot and provide logging info here”:

    https://www.politepix.com/forums/topic/install-issues-and-their-solutions/

    Thanks!

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