Simple NSSpeechRecognizer code, not working!

Discussion in 'Mac Programming' started by Monaj, Feb 12, 2010.

  1. Monaj macrumors regular

    May 24, 2009
    Hi all,

    I noticed NSSpeechRecognizer in ADC library and I found it to be very interesting, so to play with it I prepared a simple application which will just listen the command and if recognized it displays it in log.

    The code used is:

    - (id)init {
    	if (self = [super init]) {
    		// Insert code here to initialize your application 
    		NSArray *cmds = [NSArray arrayWithObjects:@"A",@"B", @"C",@"alpha",@"beta",@"vodka",@"wine",nil]; 
    		recog = [[NSSpeechRecognizer alloc] init]; // recog is an ivar
    		[recog setCommands:cmds];
    		[recog setDelegate:self];
    	return self;
    - (IBAction)listen:(id)sender
    {   NSLog(@"listen:");
        if ([sender state] == NSOnState) { // listen
    		[recog startListening];
        } else {
    		[recog stopListening];
    - (void)speechRecognizer:(NSSpeechRecognizer *)sender didRecognizeCommand:(id)aCmd {
    	NSLog(@"speechRecognizer: %@",(NSString *)aCmd);
    I tried it many times for the commands registered but I was unable to get none of the messages in log, in delegate :(

    There was always some noise in the background.. could this be the reason for it or I have done something wrong in the code??

    Can anyone suggest me some solution for it??


  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    First, have you calibrated the recognizer in the appropriate pane of the Speech system preference? If you can't get it working there, then it certainly won't work in your program.

    Second, have you done any searches for other examples using NSSpeechRecognizer? Try googling the search terms NSSpeechRecognizer example.
  3. Monaj thread starter macrumors regular

    May 24, 2009
    ok.. I will definitely check and ensure it to be working correct!

    ok.. I will definitely look for some other examples



Share This Page