• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Problems with NSSpeechSynthesizer and Foundation tool?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problems with NSSpeechSynthesizer and Foundation tool?


  • Subject: Re: Problems with NSSpeechSynthesizer and Foundation tool?
  • From: Bill Bumgarner <email@hidden>
  • Date: Fri, 21 Jul 2006 18:54:55 -0700

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.



_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Problems with NSSpeechSynthesizer and Foundation tool?
      • From: William Squires <email@hidden>
References: 
 >Problems with NSSpeechSynthesizer and Foundation tool? (From: William Squires <email@hidden>)

  • Prev by Date: Re: Assembly view
  • Next by Date: Re: Writing application without Interface Builder
  • Previous by thread: Re: Problems with NSSpeechSynthesizer and Foundation tool?
  • Next by thread: Re: Problems with NSSpeechSynthesizer and Foundation tool?
  • Index(es):
    • Date
    • Thread