让PocketSphinx识别说出的字符串是否包含单词?

时间:2012-06-23 14:03:18

标签: objective-c ios5 speech-recognition

我正在研究iOS的语音控制程序,并使用Pocketsphinx作为我的识别引擎。我想让它识别一个口头命令是否包含单词“Morning”并使用morningGreetings数组中的一个短语进行响应。我的代码看起来像这样 -

if([hypothesis rangeOfString:@"morning"].location == !NSNotFound) {
    NSString *text= [morningGreetings objectAtIndex:arc4random() % [morningGreetings count]];;
    [self.fliteController say:[NSString stringWithFormat:text] withVoice:self.firstVoiceToUse];
}

但是,使用此代码时,如果“Morning”是语音字符串中的第一个单词,则识别器仅会执行该命令。我希望它回应“早上好”,“早上好,不是吗”,“今天早上你好吗?”等等。我可以改变什么来实现这一目标?

1 个答案:

答案 0 :(得分:1)

  

我希望它能识别口头命令是否包含单词“Morning”(...)但是,使用此代码时,如果“Morning”是说出的字符串中的第一个单词,识别器只会执行该命令。

您的条件location == !NSNotFound相当于location == 0,因为!NSNotFound等于0,因此只有在“morning”是字符串中的第一个单词时才会执行。你想要的是location != NSNotFound

改变条件如下:

if ([hypothesis rangeOfString:@"morning"].location != NSNotFound) { ... }
相关问题