Mac Forums

Mac Forums (http://www.mac-forums.com/forums/)
-   OS X - Development and Darwin (http://www.mac-forums.com/forums/os-x-development-darwin/)
-   -   NSSpeechSynthesizer not calling delegate methods (http://www.mac-forums.com/forums/os-x-development-darwin/256697-nsspeechsynthesizer-not-calling-delegate-methods.html)

skot 11-09-2011 07:33 PM

NSSpeechSynthesizer not calling delegate methods
 
Anybody had any luck using an NSSpeechSynthesizerDelegate? None of my delegate messages are being called. Here's the code:

Code:

//  main.m

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

@interface SynthesizerDelegate : NSObject <NSSpeechSynthesizerDelegate>
@end

@implementation SynthesizerDelegate
- (void)speechSynthesizer:(NSSpeechSynthesizer *)sender willSpeakWord:(NSRange)characterRange ofString:(NSString *)string {
  printf("speaking word ");
  printf("%s \n", [[string substringWithRange:characterRange] UTF8String]);
}
- (void)speechSynthesizer:(NSSpeechSynthesizer *)sender didFinishSpeaking:(BOOL)finishedSpeaking {
  printf("finished speaking\n");
}
@end

int main (int argc, const char * argv[])
{
  NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
 
  NSString *input = @"I am not an animal. I am a man.";
 
  NSSpeechSynthesizer *synthesizer = [[NSSpeechSynthesizer alloc] init];
  SynthesizerDelegate *delegate = [[SynthesizerDelegate alloc] init];
  [synthesizer setDelegate:delegate];
 
  [synthesizer startSpeakingString:input];
 
  while ([synthesizer isSpeaking]) {
    sleep(1);
  }
 
  [synthesizer release];
  [delegate release];
 
  [pool drain];
  return 0;
}



All times are GMT -4. The time now is 09:48 PM.

Powered by vBulletin
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.