Forums
New posts
Articles
Product Reviews
Policies
FAQ
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Menu
Log in
Register
Install the app
Install
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
NSSpeechSynthesizer not calling delegate methods
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="skot" data-source="post: 1323740" data-attributes="member: 222558"><p>Anybody had any luck using an NSSpeechSynthesizerDelegate? None of my delegate messages are being called. Here's the code:</p><p></p><p>[CODE]</p><p>// main.m</p><p></p><p>#import <Foundation/Foundation.h></p><p>#import <AppKit/AppKit.h></p><p></p><p>@interface SynthesizerDelegate : NSObject <NSSpeechSynthesizerDelegate></p><p>@end</p><p></p><p>@implementation SynthesizerDelegate</p><p>- (void)speechSynthesizer:(NSSpeechSynthesizer *)sender willSpeakWord:(NSRange)characterRange ofString:(NSString *)string {</p><p> printf("speaking word ");</p><p> printf("%s \n", [[string substringWithRange:characterRange] UTF8String]);</p><p>}</p><p>- (void)speechSynthesizer:(NSSpeechSynthesizer *)sender didFinishSpeaking:(BOOL)finishedSpeaking {</p><p> printf("finished speaking\n");</p><p>}</p><p>@end</p><p></p><p>int main (int argc, const char * argv[])</p><p>{</p><p> NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];</p><p> </p><p> NSString *input = @"I am not an animal. I am a man.";</p><p> </p><p> NSSpeechSynthesizer *synthesizer = [[NSSpeechSynthesizer alloc] init];</p><p> SynthesizerDelegate *delegate = [[SynthesizerDelegate alloc] init];</p><p> [synthesizer setDelegate:delegate];</p><p> </p><p> [synthesizer startSpeakingString:input];</p><p> </p><p> while ([synthesizer isSpeaking]) {</p><p> sleep(1);</p><p> }</p><p> </p><p> [synthesizer release];</p><p> [delegate release];</p><p> </p><p> [pool drain];</p><p> return 0;</p><p>}</p><p>[/CODE]</p></blockquote><p></p>
[QUOTE="skot, post: 1323740, member: 222558"] 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; } [/CODE] [/QUOTE]
Verification
Post reply
Forums
macOS & iOS Developer Playground
macOS - Development and Darwin
NSSpeechSynthesizer not calling delegate methods
Top