[Resolved] OpenEarsEventsObserver not working properly

Home Forums OpenEars [Resolved] OpenEarsEventsObserver not working properly

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

  • Author
    Posts
  • #1017607
    phunkytube
    Participant

    Are there any known issues (read: any past issues) with the OpenEarsEventsObserverDelegate protocol? When I send startOpenEarsLogging to the OpenEarsLogging class, it indicates that my implementation of PocketsphinxController’s speech recognition is working and that the system recognizes my speech correctly. But none of the delegate methods are being fired, and I know I’ve hooked everything up correctly. Thanks!

    #1017608
    Halle Winkler
    Politepix

    Welcome,

    Nope, no reported issues with this in 3 years. Even though you’ve checked it out, it’s possible that there is something minor that isn’t quite right — would you like to show your code so I can check?

    #1017609
    phunkytube
    Participant

    Hi Halle, thanks for the swift reply! My code is the following (with names replaced for simplicity):

    // OpenEarsWrapper.h
    #import <Foundation/Foundation.h>
    #import <OpenEars/OpenEarsEventsObserver.h>
    
    @interface OpenEarsWrapper : NSObject <OpenEarsEventsObserverDelegate>
    
    - (id)initAndStartListeningWithWordsArray:(NSArray *)_words filename:(NSString *)_filename;
    
    @end
    
    // OpenEarsWrapper.m
    #import "OpenEarsWrapper.h"
    #import <OpenEars/LanguageModelGenerator.h>
    #import <OpenEars/PocketsphinxController.h>
    #import <OpenEars/OpenEarsLogging.h>
    
    @interface OpenEarsWrapper ()
    
    @property (nonatomic, strong) OpenEarsEventsObserver *openEarsEventsObserver;
    
    @property (nonatomic, strong) NSString *languageModelPath;
    @property (nonatomic, strong) NSString *dictionaryPath;
    
    @property (nonatomic, strong) PocketsphinxController *pocketSphinxController; // out of curiosity why is the 's' in "sphinx" lowercase???
    
    @end
    
    @implementation OpenEarsWrapper
    
    @synthesize openEarsEventsObserver;
    @synthesize languageModelPath, dictionaryPath;
    @synthesize pocketSphinxController;
    
    - (id)initAndStartListeningWithWordsArray:(NSArray *)_words filename:(NSString *)_filename {
    	self = [super init];
    	
    	if (self) {
    		//[OpenEarsLogging startOpenEarsLogging];
    		
    		openEarsEventsObserver = [[OpenEarsEventsObserver alloc] init];
    		[openEarsEventsObserver setDelegate:self];
    		
    		LanguageModelGenerator *languageModelGenerator = [[LanguageModelGenerator alloc] init];
    		
    		NSError *error = [languageModelGenerator generateLanguageModelFromArray:_words withFilesNamed:_filename];
    		
    		NSDictionary *languageGeneratorResults = nil;
    		
    		if ([error code] == noErr) {
    			languageGeneratorResults = [error userInfo];
    			
    			languageModelPath = [languageGeneratorResults objectForKey:kLanguageModelPathKey];
    			dictionaryPath = [languageGeneratorResults objectForKey:kDictionaryPathKey];
    		} else {
    			NSLog(@"Error: %@", [error localizedDescription]);
    			return self;
    		}
    		
    		pocketSphinxController = [[PocketsphinxController alloc] init];
    		
    		[pocketSphinxController startListeningWithLanguageModelAtPath:languageModelPath dictionaryAtPath:dictionaryPath languageModelIsJSGF:NO];
    	}
    	
    	return self;
    }
    
    - (void)pocketsphinxDidReceiveHypothesis:(NSString *)hypothesis recognitionScore:(NSString *)recognitionScore utteranceID:(NSString *)utteranceID {
    	NSLog(@"why doesn't this fire!!!!");
    }
    
    @end
    #1017612
    Halle Winkler
    Politepix

    Does it work if you use the lazy allocation style shown in the tutorial and sample app?

    #1017613
    phunkytube
    Participant

    Unfortunately not. It’s not an issue with my device, either, since the sample app runs correctly. And the ‘private’ instance variables (instead of, say, in the public header interface declaration) aren’t the problem either :(

    #1017617
    Halle Winkler
    Politepix

    Does the sample app work for you? Do any of the delegate methods used in the sample app work in your app?

    #1017619
    phunkytube
    Participant

    Perfectly.

    No, the delegate methods used in the sample app don’t work correctly in my app – none of the delegate methods are called. I can’t imagine what is wrong with my setup… Do you have any other ideas of where to look?

    #1017620
    Halle Winkler
    Politepix

    Very interesting. Do you want to send it over, or send over a reduced version if you have some IP in there that you don’t want to email? If so you can drop me a note via the contact form at https://www.politepix.com/contact and I’ll get back to you with an email address.

    // out of curiosity why is the ‘s’ in “sphinx” lowercase???

    Pocketsphinx isn’t camel-cased: https://cmusphinx.sourceforge.net
    Just respecting their orthography.

    #1017621
    phunkytube
    Participant

    Will do, thanks!

    It seems inconsistent on their website. Although the second most recent blog post has “Pocketsphinx” in the title, it also has “PocketSphinx” in the body. The API docs also have “PocketSphinx” (http://cmusphinx.sourceforge.net/api/pocketsphinx/). :)

    #1017623
    Halle Winkler
    Politepix

    Yep, you can also find incidences of it all-lowercase. Well, CMU is a research institution so they probably don’t worry much about their brand ID :) .

    #1017632
    Halle Winkler
    Politepix

    Hi,

    Thanks for waiting. The minor issue in the test app is that it has a slightly idiosyncratic accessor style by providing itself to the hosting class as a non-singleton class method that initializes other multithreaded or thread-conscious and persistence-needing objects inside of that class method by invoking their inits inside the class init method, and then returns.

    This started working for me when I made it a little more boring by removing the class method, made the wrapper class a property of the hosting class, instantiated it with the standard init in that class, and then did all of the setup in a separate method on the already-instantiated object.

    So I ultimately had no “+” method, used the default init, and had a method where I put all the setup that used to be in the class method, called:
    – (void) setupWithWordsArray:(NSArray *)_words filename:(NSString *)_filename;

    That got called by the wrapper object (as a class property of the hosting class) once it was instantiated.

    Without more time to look into it, I don’t know if the fundamental issue is multithreading related, something with ARC optimization, or just that the observer delegate needs the observing object to have returned from its initialization. I did not continue to troubleshoot how the delegate of the wrapper functioned since I had to stop after the OpenEarsEventsObserver started working, so I don’t know if those are working or not. Let me know if this helps or if you need more details. It’s also a good idea to put all the OpenEars code into your root view controller rather than the app delegate since it is business code. You can still instantiate OpenEarsEventsObservers wherever you need them, so this won’t pin you down to a single view controller.

    -Halle

    #1020216
    nbhagat
    Participant

    I am also facing similar issue like phunkytube mentioned. OpenEarsLogging shows perfect logs of “listening”, “Speech detected…” when I perform actions, but none of the delegate methods are called. I am converting the whole ViewController’s functionality to a class super-classed by NSObject.

    #1020217
    Halle Winkler
    Politepix

    Welcome,

    Just take a look at the sample app or tutorial which have different known-to-work examples and compare either or both with your implementation – it will come down to memory management or similar.

    #1020218
    Halle Winkler
    Politepix

    Also, be sure to compare both the header and implementations, since setting up delegates has to start with importing their protocols in the header.

    #1020220
    nbhagat
    Participant

    Thanks a lot. I just figured out to make it working. I created property for my class and then initialised the class using that property. It works as expected now. :)

    #1020221
    Halle Winkler
    Politepix

    Excellent, glad to hear it.

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