Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Jmasterman

macrumors newbie
Original poster
Jul 1, 2010
5
0
Hi
I am having problems with NSSpeechRecognizer.

this is the this is SpeechRecAppDelegate.M file
Code:
@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");
		return;
    }
	
    else if ([(NSString *)aCmd isEqualToString:@"Stop"]) {
		NSLog(@"Stop called");
        return;
    }
    else if ([(NSString *)aCmd isEqualToString:@"Roll over"]) {
		NSLog(@"Rollover called");
        // .... some response here...
    }
	else {
		NSLog(@"hello");
	}

}


@end
It give me a warning [recog setDelegate:self]; it says (class SpeechRecAppDelegate does not implement the NSSpeechRecogizerDelegate protocol)
And here is the header file.
Code:
#import <Cocoa/Cocoa.h>

@interface SpeechRecAppDelegate : NSObject  {
    NSWindow *window;
	NSSpeechRecognizer* recog;
}



@property (assign) IBOutlet NSWindow *window;

@end
Thank you in advance
 

chown33

Moderator
Staff member
Aug 9, 2009
10,747
8,420
A sea of green
The problem is exactly what the message says:
your class doesn't implement the NSSpeechRecognizerDelegate protocol.

To make it do that, change this:
Code:
@interface SpeechRecAppDelegate : NSObject  {
to this:
Code:
@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.)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.