0

我正在尝试为我的应用程序创建简单的帮助程序类,它将加载打开的耳朵默认值。问题是一切似乎都很正常,但是当我创建新的帮助程序对象并运行方法startListening时,它什么也没做。

我认为问题在于设置委托,但我无法弄清楚

OpenEarsHelper.h

#import <Foundation/Foundation.h>
#import <OpenEars/PocketsphinxController.h>
#import <OpenEars/LanguageModelGenerator.h>
@interface OpenEarsHelper : NSObject<OpenEarsEventsObserverDelegate>{
    OpenEarsEventsObserver *openEarsEventsObserver;
    PocketsphinxController *pocketsphinxController;
}
@property (strong, nonatomic) OpenEarsEventsObserver *openEarsEventsObserver;
@property (strong, nonatomic) PocketsphinxController *pocketsphinxController;
-(void)prepare;
@end

OpenEarsHelper.m

#import "OpenEarsHelper.h"

@implementation OpenEarsHelper
@synthesize openEarsEventsObserver;

-(void)prepare{

    [self.openEarsEventsObserver setDelegate:self];//Problem should be here

    LanguageModelGenerator *lmGenerator = [[LanguageModelGenerator alloc] init];
    NSArray *words = [NSArray arrayWithObjects:@"WORD", @"STATEMENT", @"OTHER WORD", @"A PHRASE", nil];
    NSString *name = @"NameIWantForMyLanguageModelFiles";
    NSError *err = [lmGenerator generateLanguageModelFromArray:words withFilesNamed:name];


    NSDictionary *languageGeneratorResults = nil;
    NSString *lmPath = nil;
    NSString *dicPath = nil;
    languageGeneratorResults = [err userInfo];
    lmPath = [languageGeneratorResults objectForKey:@"LMPath"];
    dicPath = [languageGeneratorResults objectForKey:@"DictionaryPath"];
    [self.pocketsphinxController startListeningWithLanguageModelAtPath:lmPath dictionaryAtPath:dicPath languageModelIsJSGF:NO];
}

- (void) pocketsphinxDidReceiveHypothesis:(NSString *)hypothesis recognitionScore:(NSString *)recognitionScore utteranceID:(NSString *)utteranceID {
    NSLog(@"The received hypothesis is %@ with a score of %@ and an ID of %@", hypothesis, recognitionScore, utteranceID);
}

- (PocketsphinxController *)pocketsphinxController {
    if (pocketsphinxController == nil) {
        pocketsphinxController = [[PocketsphinxController alloc] init];
    }
    return pocketsphinxController;
}

- (OpenEarsEventsObserver *)openEarsEventsObserver {
    if (openEarsEventsObserver == nil) {
        openEarsEventsObserver = [[OpenEarsEventsObserver alloc] init];
        openEarsEventsObserver.delegate = self;
    }
    return openEarsEventsObserver;
}
@end

我在viewDidLoad像这样的方法中使用它

 OpenEarsHelper *helper=[[OpenEarsHelper alloc]init];
  [helper prepare];
4

0 回答 0