NSSpeechRecognizer problem

Discussion in 'Mac Programming' started by Jmasterman, Jul 1, 2010.

  1. Jmasterman macrumors newbie

    Jul 1, 2010
    I am having problems with NSSpeechRecognizer.

    this is the this is SpeechRecAppDelegate.M file
    @implementation SpeechRecAppDelegate
    @synthesize window;
    - (id)init {
        self = [super init];
        if (self) {
            NSArray *cmds = [NSArray arrayWithObjects:@"Forward",
    						 @"Stop", @"Left", @"Right", @"Backwards", @"Roll over", nil];
            recog = [[NSSpeechRecognizer alloc] init]; // recog is an ivar
            [recog setCommands:cmds];
            [recog setDelegate:self];
        return self;
    -(void)speechRecognizer:(NSSpeechRecognizer *)sender
    didRecognizeCommand:(id)aCmd {
    	if ([(NSString *)aCmd isEqualToString:@"Forward"]) {
    		NSLog(@"Forward called");
        else if ([(NSString *)aCmd isEqualToString:@"Stop"]) {
    		NSLog(@"Stop called");
        else if ([(NSString *)aCmd isEqualToString:@"Roll over"]) {
    		NSLog(@"Rollover called");
            // .... some response here...
    	else {
    It give me a warning [recog setDelegate:self]; it says (class SpeechRecAppDelegate does not implement the NSSpeechRecogizerDelegate protocol)
    And here is the header file.
    #import <Cocoa/Cocoa.h>
    @interface SpeechRecAppDelegate : NSObject  {
        NSWindow *window;
    	NSSpeechRecognizer* recog;
    @property (assign) IBOutlet NSWindow *window;
    Thank you in advance
  2. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    The problem is exactly what the message says:
    your class doesn't implement the NSSpeechRecognizerDelegate protocol.

    To make it do that, change this:
    @interface SpeechRecAppDelegate : NSObject  {
    to this:
    @interface SpeechRecAppDelegate : NSObject <NSSpeechRecognizerDelegate>  {
    Then review your Objective-C language reference (book or webpage) on how to declare your class as implementing a given protocol.

    If you're using example code, then NSSpeechRecognizerDelegate wasn't required from the delegate until 10.6. So it could be your example is out of date, or you're using 10.6 as the deployment target when you should be using 10.5. Can't tell more without details of what you're working from.

    (Standard disclaimers apply:
    Use with caution.
    The posted code has not been tested, and may contain errors or typos.
    Repost if errors occur, including actual error message text.)

Share This Page