Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NSSpeechRecognizer example

Ok so I need to do this:

Wait for command, "Goodnight". Then run an action.

Can someone explain how do accomplish this?

like image 853
objectiveccoder001 Avatar asked May 24 '11 00:05

objectiveccoder001


1 Answers

Try this website:

http://www.cocoadev.com/index.pl?NSSpeechRecognizer

And modify as such:

NSSpeechRecognizer *listen;
NSArray *cmds = [NSArray arrayWithObjects:@"goodnight",nil];
listen = [[NSSpeechRecognizer alloc] init];
[listen setCommands:cmds];
[listen setDelegate:self];
[listen setListensInForegroundOnly:NO];
[listen startListening];
[listen setBlocksOtherRecognizers:YES];

- (void)speechRecognizer:(NSSpeechRecognizer *)sender didRecognizeCommand:(id)aCmd {
    if ([(NSString *)aCmd isEqualToString:@"goodnight"]) {
        [self performSelector:@selector(goodnightMethod:)];
    }
}

Your method for handling good night would be (with accordance to what I have written):

-(void)goodnightMethod:(id)sender {
    //Do stuff here...
}
like image 146
Dair Avatar answered Sep 27 '22 19:09

Dair