followed tutorial, not working for me

Home Forums OpenEars followed tutorial, not working for me

Tagged: , ,

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

  • Author
    Posts
  • #1022311
    JonLocate
    Participant

    I need to implement voice recognition in my application, so I decided to try the OpenEars SDK. I’ve followed the tutorial on your website exactly but it is not working for me. I get no errors and the OpenEarsLogging is not showing any errors, it gets as far as creating the language model but then does not do anything else. I set the openEarsEventObserverDelegate to self and then startListeningWithLanguageModel, but nothing happens. I was expecting some of the logs in the delegate methods to log but they don’t.

    Heres is my code

    can be seen at stack overflow if you’d like to see the code better formatted

    http://stackoverflow.com/questions/25408087/ios-openears-tutorial-not-working-for-me

    .h

    #import <UIKit/UIKit.h>
    #import <OpenEars/PocketsphinxController.h>
    #import <OpenEars/AcousticModel.h>
    #import <OpenEars/OpenEarsEventsObserver.h>

    @interface SpeechViewController : UIViewController <OpenEarsEventsObserverDelegate>

    @property (strong, nonatomic) PocketsphinxController *pocketSphinxController;
    @property (strong, nonatomic) OpenEarsEventsObserver *openEarsEventObserver;

    @property (strong, nonatomic) IBOutlet UILabel *resultsLabel;

    – (IBAction)talkButton:(id)sender;

    @end

    .m

    #import “SpeechViewController.h”
    #import <OpenEars/LanguageModelGenerator.h>
    #import <OpenEars/OpenEarsLogging.h>

    @interface SpeechViewController ()

    @end

    @implementation SpeechViewController

    – (void)viewDidLoad
    {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    [_openEarsEventObserver setDelegate:self];

    [OpenEarsLogging startOpenEarsLogging];
    }

    – (void)didReceiveMemoryWarning
    {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }

    – (PocketsphinxController *)pocketSphinxController
    {
    if (_pocketSphinxController == nil)
    {
    _pocketSphinxController = [[PocketsphinxController alloc] init];
    }

    return _pocketSphinxController;
    }

    – (OpenEarsEventsObserver *)openEarsEventObserver
    {
    if (_openEarsEventObserver == nil)
    {
    _openEarsEventObserver = [[OpenEarsEventsObserver alloc] init];
    }

    return _openEarsEventObserver;
    }

    – (IBAction)talkButton:(id)sender
    {

    LanguageModelGenerator *LangGen = [[LanguageModelGenerator alloc] init];

    NSArray *words = [NSArray arrayWithObjects:@”HELLO WORLD”, @”HELLO”, @”WORLD”, @”TEST”, @”SPEECH”, @”LOCATION”, nil];
    NSString *name = @”LangModelName”;
    NSError *err = [LangGen generateLanguageModelFromArray:words withFilesNamed:name forAcousticModelAtPath:[AcousticModel pathToModel:@”AcousticModelEnglish”]];

    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]);
    }

    // was putting either here or in viewDidLoad
    //[_openEarsEventObserver setDelegate:self];

    [_pocketSphinxController startListeningWithLanguageModelAtPath:lmPath dictionaryAtPath:dicPath acousticModelAtPath:[AcousticModel pathToModel:@”AcousticModelEnglish”] languageModelIsJSGF:NO];

    }

    – (void)pocketsphinxDidReceiveHypothesis:(NSString *)hypothesis recognitionScore:(NSString *)recognitionScore utteranceID:(NSString *)utteranceID
    {
    NSLog(@”The Recieved Hypothesis is %@ with a score of %@ and an ID of %@”, hypothesis, recognitionScore, utteranceID);

    [self.resultsLabel setText:hypothesis];
    }

    – (void)pocketsphinxDidStartCalibration
    {
    NSLog(@”Calibration started”);
    }

    – (void)pocketsphinxDidCompleteCalibration
    {
    NSLog(@”Calibration is complete”);
    }

    – (void)pocketsphinxDidStartListening
    {
    NSLog(@”Now listening”);
    }

    – (void)pocketsphinxDidDetectSpeech
    {
    NSLog(@”Detecting speech”);
    }

    – (void)pocketsphinxDidDetectFinishedSpeech
    {
    NSLog(@”Finished detecting speech”);
    }

    – (void)pocketsphinxDidStopListening
    {
    NSLog(@”Stopped listening”);
    }

    – (void)pocketsphinxDidSuspendRecognition
    {
    NSLog(@”Suspended recognition”);
    }

    – (void)pocketsphinxDidResumeRecognition
    {
    NSLog(@”Resumed recognition”);
    }

    – (void)pocketsphinxDidChangeLanguageModelToFile:(NSString *)newLanguageModelPathAsString andDictionary:(NSString *)newDictionaryPathAsString
    {
    NSLog(@”Now using following language model: \n%@ and the following dictionary: %@”, newLanguageModelPathAsString, newDictionaryPathAsString);
    }

    – (void)pocketSphinxContinuousSetupDidFail
    {
    NSLog(@”PocketSphinx has failed :(“);
    }

    – (void)testRecognitionCompleted
    {
    NSLog(@”A test file submitted for recognition is now complete”);
    }

    @end

    To my eyes thats exactly the way it’s laid out in the tutorial. Does anybody have any ideas why this would not work?

    thanks very much!

    logging info

    2014-08-20 16:56:37.625 OpenEarsTest[382:60b] Starting OpenEars logging for OpenEars version 1.7 on 32-bit device: iPad running iOS version: 7.100000
    2014-08-20 16:56:40.468 OpenEarsTest[382:60b] acousticModelPath is /var/mobile/Applications/7E1E39CB-4194-4F73-B3FC-8997C8C161A0/OpenEarsTest.app/AcousticModelEnglish.bundle
    2014-08-20 16:56:40.567 OpenEarsTest[382:60b] Starting dynamic language model generation
    2014-08-20 16:56:40.574 OpenEarsTest[382:60b] Able to open /var/mobile/Applications/7E1E39CB-4194-4F73-B3FC-8997C8C161A0/Library/Caches/LangModelName.corpus for reading
    2014-08-20 16:56:40.576 OpenEarsTest[382:60b] Able to open /var/mobile/Applications/7E1E39CB-4194-4F73-B3FC-8997C8C161A0/Library/Caches/LangModelName_pipe.txt for writing
    2014-08-20 16:56:40.578 OpenEarsTest[382:60b] Starting text2wfreq_impl
    2014-08-20 16:56:40.602 OpenEarsTest[382:60b] Done with text2wfreq_impl
    2014-08-20 16:56:40.604 OpenEarsTest[382:60b] Able to open /var/mobile/Applications/7E1E39CB-4194-4F73-B3FC-8997C8C161A0/Library/Caches/LangModelName_pipe.txt for reading.
    2014-08-20 16:56:40.607 OpenEarsTest[382:60b] Able to open /var/mobile/Applications/7E1E39CB-4194-4F73-B3FC-8997C8C161A0/Library/Caches/LangModelName.vocab for reading.
    2014-08-20 16:56:40.609 OpenEarsTest[382:60b] Starting wfreq2vocab
    2014-08-20 16:56:40.611 OpenEarsTest[382:60b] Done with wfreq2vocab
    2014-08-20 16:56:40.613 OpenEarsTest[382:60b] Starting text2idngram
    2014-08-20 16:56:40.651 OpenEarsTest[382:60b] Done with text2idngram
    2014-08-20 16:56:40.658 OpenEarsTest[382:60b] Starting idngram2lm

    2014-08-20 16:56:40.672 OpenEarsTest[382:60b] Done with idngram2lm
    2014-08-20 16:56:40.673 OpenEarsTest[382:60b] Starting sphinx_lm_convert
    2014-08-20 16:56:40.687 OpenEarsTest[382:60b] Finishing sphinx_lm_convert
    2014-08-20 16:56:40.695 OpenEarsTest[382:60b] Done creating language model with CMUCLMTK in 0.126219 seconds.
    2014-08-20 16:56:40.874 OpenEarsTest[382:60b] I’m done running performDictionaryLookup and it took 0.148703 seconds
    2014-08-20 16:56:40.882 OpenEarsTest[382:60b] I’m done running dynamic language model generation and it took 0.411740 seconds

    #1022314
    Halle Winkler
    Politepix

    Welcome,

    I’ll be happy to help you out, just do me a favor and choose a single venue for asking so that I don’t have doubled work keeping track of both locations.

    #1022316
    JonLocate
    Participant

    Thank you! I deleted that Stack post.

    #1022320
    Halle Winkler
    Politepix

    Thank you! OK, the first step is to turn on verbosePocketsphinx and show me the output – if there is an issue with language or acoustic model it will be logged there.

    #1022321
    Halle Winkler
    Politepix

    The other thing is that you’re referencing the ivars throughout (they aren’t necessary and are going away in the upcoming tutorial version) but the tutorial always references the properties with self, so I would follow that convention in order to make use of the lazy initializers every time. When you show me the logging, make sure to show the complete logging without removing anything, since it can sometimes seem less important than it is.

    #1022323
    JonLocate
    Participant

    hey Halle, thanks for your replies. I’ve updated my code a little, to closer match the tutorial. Also I am not sure what you mean by ivars?

    the delegate methods are still in my code but i didn’t post them just to make the code shorter. also i turned on verbosePocketSphinx (i think) and the logging output is the same as when only using [OpenEarLogging startOpenEarsLogging].

    header file

    #import <UIKit/UIKit.h>
    #import <OpenEars/PocketsphinxController.h>
    #import <OpenEars/AcousticModel.h>
    #import <OpenEars/OpenEarsEventsObserver.h>

    @interface SpeechViewController : UIViewController <OpenEarsEventsObserverDelegate>
    {
    PocketsphinxController *pocketSphinxController;
    OpenEarsEventsObserver *openEarsEventObserver;
    }

    @property (strong, nonatomic) PocketsphinxController *pocketSphinxController;
    @property (strong, nonatomic) OpenEarsEventsObserver *openEarsEventObserver;

    @property (strong, nonatomic) IBOutlet UILabel *resultsLabel;

    – (IBAction)talkButton:(id)sender;

    @end

    implementation

    #import “SpeechViewController.h”
    #import <OpenEars/LanguageModelGenerator.h>
    #import <OpenEars/OpenEarsLogging.h>

    @interface SpeechViewController () <OpenEarsEventsObserverDelegate>

    @end

    @implementation SpeechViewController

    @synthesize pocketSphinxController;
    @synthesize openEarsEventObserver;

    – (void)viewDidLoad
    {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.

    [openEarsEventObserver setDelegate:self];

    pocketSphinxController.verbosePocketSphinx = true;

    [OpenEarsLogging startOpenEarsLogging];
    }

    – (void)didReceiveMemoryWarning
    {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
    }

    – (PocketsphinxController *)pocketSphinxController
    {
    if (pocketSphinxController == nil)
    {
    pocketSphinxController = [[PocketsphinxController alloc] init];
    }

    return pocketSphinxController;
    }

    – (OpenEarsEventsObserver *)openEarsEventObserver
    {
    if (openEarsEventObserver == nil)
    {
    openEarsEventObserver = [[OpenEarsEventsObserver alloc] init];
    }

    return openEarsEventObserver;
    }

    – (IBAction)talkButton:(id)sender
    {

    LanguageModelGenerator *LangGen = [[LanguageModelGenerator alloc] init];

    NSArray *words = [NSArray arrayWithObjects:@”HELLO WORLD”, @”HELLO”, @”WORLD”, @”TEST”, @”SPEECH”, @”LOCATION”, nil];
    NSString *name = @”LangModelName”;
    NSError *err = [LangGen generateLanguageModelFromArray:words withFilesNamed:name forAcousticModelAtPath:[AcousticModel pathToModel:@”AcousticModelEnglish”]];

    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]);
    }

    //[openEarsEventObserver setDelegate:self];

    [pocketSphinxController startListeningWithLanguageModelAtPath:lmPath dictionaryAtPath:dicPath acousticModelAtPath:[AcousticModel pathToModel:@”AcousticModelEnglish”] languageModelIsJSGF:NO];

    }

    – (void)pocketsphinxDidReceiveHypothesis:(NSString *)hypothesis recognitionScore:(NSString *)recognitionScore utteranceID:(NSString *)utteranceID
    {
    NSLog(@”The Recieved Hypothesis is %@ with a score of %@ and an ID of %@”, hypothesis, recognitionScore, utteranceID);

    [self.resultsLabel setText:hypothesis];
    }

    logging

    2014-08-21 10:03:46.900 OpenEarsTest[192:60b] Starting OpenEars logging for OpenEars version 1.7 on 32-bit device: iPad running iOS version: 7.100000
    2014-08-21 10:03:49.715 OpenEarsTest[192:60b] acousticModelPath is /var/mobile/Applications/7E1E39CB-4194-4F73-B3FC-8997C8C161A0/OpenEarsTest.app/AcousticModelEnglish.bundle
    2014-08-21 10:03:49.800 OpenEarsTest[192:60b] Starting dynamic language model generation
    2014-08-21 10:03:49.806 OpenEarsTest[192:60b] Able to open /var/mobile/Applications/7E1E39CB-4194-4F73-B3FC-8997C8C161A0/Library/Caches/LangModelName.corpus for reading
    2014-08-21 10:03:49.809 OpenEarsTest[192:60b] Able to open /var/mobile/Applications/7E1E39CB-4194-4F73-B3FC-8997C8C161A0/Library/Caches/LangModelName_pipe.txt for writing
    2014-08-21 10:03:49.811 OpenEarsTest[192:60b] Starting text2wfreq_impl
    2014-08-21 10:03:49.834 OpenEarsTest[192:60b] Done with text2wfreq_impl
    2014-08-21 10:03:49.836 OpenEarsTest[192:60b] Able to open /var/mobile/Applications/7E1E39CB-4194-4F73-B3FC-8997C8C161A0/Library/Caches/LangModelName_pipe.txt for reading.
    2014-08-21 10:03:49.838 OpenEarsTest[192:60b] Able to open /var/mobile/Applications/7E1E39CB-4194-4F73-B3FC-8997C8C161A0/Library/Caches/LangModelName.vocab for reading.
    2014-08-21 10:03:49.840 OpenEarsTest[192:60b] Starting wfreq2vocab
    2014-08-21 10:03:49.842 OpenEarsTest[192:60b] Done with wfreq2vocab
    2014-08-21 10:03:49.844 OpenEarsTest[192:60b] Starting text2idngram
    2014-08-21 10:03:49.867 OpenEarsTest[192:60b] Done with text2idngram
    2014-08-21 10:03:49.878 OpenEarsTest[192:60b] Starting idngram2lm

    2014-08-21 10:03:49.892 OpenEarsTest[192:60b] Done with idngram2lm
    2014-08-21 10:03:49.894 OpenEarsTest[192:60b] Starting sphinx_lm_convert
    2014-08-21 10:03:49.908 OpenEarsTest[192:60b] Finishing sphinx_lm_convert
    2014-08-21 10:03:49.915 OpenEarsTest[192:60b] Done creating language model with CMUCLMTK in 0.114059 seconds.
    2014-08-21 10:03:50.093 OpenEarsTest[192:60b] I’m done running performDictionaryLookup and it took 0.147953 seconds
    2014-08-21 10:03:50.101 OpenEarsTest[192:60b] I’m done running dynamic language model generation and it took 0.384307 seconds

    i doubt it has anything to do with how i imported OpenEars into my project since all the classes and methods are fully visible and showing no errors, but i could be wrong, maybe there is a missing reference to something?

    thanks very much!

    #1022324
    Halle Winkler
    Politepix

    Quick question –– we could troubleshoot this some more and I’m sure a straightforward reason will shake out once we get the logging turned on (I’m almost certain at this point that it is because you’re referencing the ivars you created with the underscores in front of them –– an ivar is an instance variable of a class and that convention with the underscore is intended to make it clear when an instance variable is being referenced rather than a property, but the tutorial code is designed to only ever reference by class property), but why don’t you just exactly copy and paste the tutorial code since it is known to work?

    The tutorial is designed to avoid any possible memory management or referencing mistakes that can happen with objects that perform many asynchronous operations with callbacks over their lifetime, and the changes you’ve made to it aren’t that minor since they change the way that those objects are addressed in a way that works around those failsafes.

    Can you start by doing a complete copy and paste so we can have a clean slate, and then once that is working, go ahead and ask me the questions about changes you’d like to make that led to making those alterations?

    #1022325
    JonLocate
    Participant

    ok, i’ll copy and paste the tutorial and see how i get on. Is this line the correct way to start the verbosePocketSphinx logging?

    pocketSphinxController.verbosePocketSphinx = true;

    thanks

    #1022326
    Halle Winkler
    Politepix

    Yes, if you are successfully addressing the object after it has been instantiated (but in that case you would do so using self.pocketsphinxController as shown in the tutorial, or you would make the call to set verbosePocketsphinx inside of the lazy allocation method). You can also see an example of all of that including a call to verbosePocketsphinx in the sample app that ships with the framework.

    #1022327
    JonLocate
    Participant

    well it works! I completely copy and pasted the tutorial and it worked perfectly! I didnt’ think I needed to create those instance variables in the .h file and synthesize them in the .m, but I guess I needed to! How come you have to do it this way instead of just referencing the properties? I’ve seen it work fine for other things, for example, Apples Location Manager class. You create a property of a LocationManager, then you can set the class you are working on as the delegate and reference it as self.LocationManager or _LocationManager and it works fine without having to create the ivars or synthesize them. I guess they are completey differnt classes though!

    Thanks for the help!

    #1022328
    Halle Winkler
    Politepix

    You’re welcome!

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