I’m working on a voice-controlled program for iOS and using Pocketsphinx as my recognition engine. I want it to recognize whether a spoken command contains the word “Morning” and respond with one of the phrases in the morningGreetings array. My code looks like this-
if([hypothesis rangeOfString:@"morning"].location == !NSNotFound) {
NSString *text= [morningGreetings objectAtIndex:arc4random() % [morningGreetings count]];;
[self.fliteController say:[NSString stringWithFormat:text] withVoice:self.firstVoiceToUse];
}
However, with this code the recognizer only exectues the command if “Morning” is the FIRST word in the spoken string. I want it to respond to “Good morning”, “Nice morning, isn’t it”, “How are you this morning?”, etc. What can I change to achieve this?
Your condition
location == !NSNotFoundis equivalent tolocation == 0because!NSNotFoundequals 0, therefore it only executes if “morning” is the first word in the string. What you want islocation != NSNotFound.Change the condition like so: