繁体   English   中英

从另一个类/控制器(IOS,Objective c)获取字符串时,打开耳朵文本到语音(语音)不起作用

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

我对objective c和OpenEars很陌生,所以如果我有一些混乱的代码并且我迷失在非常简单的问题中,请原谅我。

无论如何,我在这个应用程序中有两个控制器。 第一个是默认的 ViewController,第二个是我创建的名为 ReplyManagerController 的新控制器。

ViewController 中的代码基本上使用教程中的代码,并进行了一些(可能更多一些)更改。

编辑:

该应用程序应该是一个基本的应用程序,用户说一些东西,应用程序回复。

但最初的问题是,当我的 ViewController 从另一个类/控制器获取字符串时,我无法显示字符串或 TTS 工作。

我下面的答案提到这可能是因为我的另一个类在没有初始化 self.fliteController 的情况下调用了我的 ViewController。

我将如何使用初始化的 self.fliteController 来初始化 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;

}

任何帮助都会很棒! 谢谢!

回复经理.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];
      }
}

编辑2:

viewDidLoad 方法

 - (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];
}
ViewController* getReply = [[ViewController alloc] init];

在这里,您初始化一个新的ViewController ,它最有可能没有定义self.fliteController 您需要重用 previos 控制器,例如像这样:

   [replyObject speechResult:(NSString*)strResult viewController:self];

所以你可以稍后使用已经初始化的viewController 总的来说,最好事先初始化像viewControllerreplyController这样的对象,而不是在回调方法中。

听起来像是在初始化之前尝试使用fliteController的计时问题。

在您的ViewController类中,您在哪里为fliteController属性赋值? 在初始化程序中? -(void)viewDidLoad

ReplyManagerController添加:

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

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

以上是否解决了问题? 如果是这样,您可能正在-(void)viewDidLoad初始化fliteController 两个NSLog语句的结果是什么?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM