Skip navigation.
 
mlRe: Problems with NSSpeechSynthesizer and Foundation tool?
FROM : William Squires
DATE : Sun Jul 23 15:41:23 2006

Okay then, how do I get my foundation tool to wait for the speech
synthesizer to finish before exiting the program? Or is that even the
cause of my problem (no sound, but no crash either)? Is
NSSpeechSynthesizer even compatible with foundation tools?
  Would an NSNotification trick work, or do those - too - rely on the
run loop?

On Jul 21, 2006, at 8:54 PM, Bill Bumgarner wrote:

> On Jul 21, 2006, at 6:12 PM, William Squires wrote:

>> Hi
>>  I'm just trying to write a simple "Hello, world" program that
>> speaks the string rather than prints it. I made a simple class,
>> SpeakMe, to hold the 'guts' of the code. Here's the implementation
>> (SpeakMe.m):
>>
>> #import <AppKit/NSSpeechSynthesizer.h>
>> #import "SpeakMe.h"
>>
>> @implementation SpeakMe
>> -(id) init
>> {
>> NSLog(@"init\n");
>> self = [super init];
>> if (self)
>>     {
>>     iDidFinishSpeaking = NO;
>>     speak = [[NSSpeechSynthesizer alloc] init];
>>     [speak setDelegate:self];
>>     }
>> return self;
>> }
>>
>> -(void) doSpeak
>> {
>> NSLog(@"doSpeak\n");
>> NSString *text = @"Hello, Objective See";
>> [speak startSpeakingString:text];
>> for ( ;1 ; )
>>     {
>>     if (iDidFinishSpeaking = YES)
>>         {
>>         break;
>>         }
>>     }
>> }
>>
>> -(void) speechSynthesizer:(NSSpeechSynthesizer *)sender
>> didFinishSpeaking:(BOOL)finished
>> {
>> NSLog(@"speechSynthesizer:didFinishSpeaking\n");
>> iDidFinishSpeaking = YES;
>> }
>>
>> @end
>>
>>  In main.m, I set up a "SpeakMe *" as:
>>
>> SpeakMe *speaker = [[SpeakMe alloc] init];
>>
>> as one would expect. The NSLog shows it (the init method) gets
>> called. This sets up its speechSynthesizer:didFinishSpeaking delegate
>> (I hope...). I then call [speaker doSpeak]; in the next line. It,
>> too, fires - and NSLog shows that. But, shouldn't the "deliberate
>> infinite loop" keep code execution in the doSpeak method until the
>> delegate gets called to set the 'iDidFinishSpeaking' variable to YES?
>> NSLog shows that the program exits normally, so - clearly - the loop
>> exited, but my output never shows that the
>> speechSynthesizer:didFinishSpeaking delegate got called...
>>  What's going on here?

>
> Two problems:
>
> First, as pointed out by someone else, the if() statements test is
> incorrect -- you need ==, no =.
>
> But that won't actually fix your code.  Once that change is made,
> your code is effectively going to lock up in the for() loop. 
> Generally, you need to have a running run loop for delegate methods
> and other kinds of intra-thread communication to work as expected. 
> The run loop's purpose is to sit around and wait for something
> exciting to happen and then dispatch that excitement into your code. 
> Your for() loop will prevent the run loop from running and, thus,
> prevent the NSSpeechSynthesizer from sending the appropriate delegate
> method calls.
>
>
>

William H Squires Jr
4400 Horizon Hill #4006
San Antonio, TX 78229
<email_removed> <- remove the .nospam

Related mailsAuthorDate
mlProblems with NSSpeechSynthesizer and Foundation tool? William Squires Jul 22, 03:12
mlRe: Problems with NSSpeechSynthesizer and Foundation tool? Brian Ganninger Jul 22, 03:39
mlRe: Problems with NSSpeechSynthesizer and Foundation tool? Bill Bumgarner Jul 22, 03:54
mlRe: Problems with NSSpeechSynthesizer and Foundation tool? William Squires Jul 23, 15:41
mlRe: Problems with NSSpeechSynthesizer and Foundation tool? Jordan Krushen Jul 24, 11:05