objective-cxcodeopenears

Open ears text to speech (voice) not working when getting string from another class/controller (IOS, Objective c)


I am very new to objective c and OpenEars so please forgive me if I have some messy code and if I am lost in very simple problem.

Anyhow, I have two controllers in this application. The first being the default ViewController and the second one being a new one that I made called ReplyManagerController.

The code in the ViewController basically uses the one in the tutorial with some (maybe more some) changes.

EDIT:

The app is supposed to be a basic app where a user says something and the app replies.

But the original problem was that I could not get the string to display or TTS to work when my ViewController got it's string from another class/controller.

The answer in my below mentions that it was probably because my other class was calling my ViewController without the self.fliteController initialized.

How would I initialize the ViewController with self.fliteController initialized?

ViewController.m

- (void) pocketsphinxDidReceiveHypothesis:(NSString *)hypothesis recognitionScore:(NSString *)recognitionScore utteranceID:(NSString *)utteranceID {

NSString *strResult = hypothesis; //speech to text to string

ReplyManager* replyObject = [[ReplyManager alloc] init];
[replyObject speechResult:(NSString*)strResult viewController:self];
}

- (void) getReply:(NSString*)replyStr{

[self.fliteController say:replyStr withVoice:self.slt];

[self updateText:replyStr];
}

- (IBAction)updateText:(NSString*)replyStr{
labelOne.text = replyStr;
labelOne.adjustsFontSizeToFitWidth = YES;
labelOne.minimumFontSize = 0;

}

Any help will be great! Thanks!

ReplyManager.m

  - (void) speechResult:(NSString*)strResult {

    NSString *replystr;
    NSString *greetings = @"Hi!";
    NSString *sorry = @"Sorry I didn't catch that?";

    ViewController* getReply = [[ViewController alloc] init];

    if ([strResult isEqualToString:@"HELLO"])
      { 
       replystr = greetings;
       [getReply getReply:(NSString*)replystr];
      }
    else
      {
       replystr = sorry;
       [getReply getReply:(NSString*)replystr];
      }
}

EDIT 2:

viewDidLoad Method

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

   self.fliteController = [[OEFliteController alloc] init];
   self.slt = [[Slt alloc] init];

   self.openEarsEventsObserver = [[OEEventsObserver alloc] init];
   [self.openEarsEventsObserver setDelegate:self];
}

Solution

  • It sounds like a timing issue where you're trying to use fliteController before it's been initialized.

    In your ViewController class, where do you assign a value to the fliteController property? In an initializer? -(void)viewDidLoad?

    In ReplyManagerController add:

    ViewController* getReply = [[ViewController alloc] init];
    
    // Add these lines
    NSLog(getReply.fliteController); // Is this nil?
    [getReply.view layoutIfNeeded];
    NSLog(getReply.fliteController); // Is it still nil?
    

    Does the above fix the problem? If so, you're probably initializing fliteController in -(void)viewDidLoad. What's the result of the two NSLog statements?