SpeekLine sample problem


#1
  • (void)speechSynthesizer:(NSSpeechSynthesizer *)sender
    didFinishSpeaking:(BOOL)finishedSpeaking{
    [color=#FF0000]NSLog(@“complete = %d”,finishedSpeaking);[/color]
    //code…
    }

Before call “setVoice:” message, Log was “complete = 1”.
But After call “[color=#FF0000]setVoice:[/color]” message, Log was “[color=#FF0000]complete = 0[/color]”.


#2

Could you post all of your code, using the code format block?

That way we can take a look.


#3
#pragma mark - NSTableViewDelegate

- (void)tableViewSelectionDidChange:(NSNotification *)notification
{
	NSInteger row = [_tableView selectedRow];
	if (row == -1)
		return;
	NSString *selectedVoice = [_voices objectAtIndex:row];
	[_speechSynth setVoice:selectedVoice];
	NSLog(@"New voice = %@", selectedVoice);
}

#pragma mark - NSSpeechSynthesizerDelegate

- (void)speechSynthesizer:(NSSpeechSynthesizer *)sender
		didFinishSpeaking:(BOOL)finishedSpeaking
{
	NSLog(@"finishedSpeaking = %d", finishedSpeaking);
	[_stopButton setEnabled:NO];
	[_speakButton setEnabled:YES];
	[_tableView setEnabled:YES];
}

This code is the book sample code.(Chapter 6. SpeakLine Sample)
I didn’t change the code.

  1. First, Run Application and click “Speak” button -> “finishedSpeaking = 1”
  2. Select another tableview cell and click “Speak” button -> “finishedSpeaking = 0”
  3. Click again “Speak” button -> “finishedSpeaking = 1”

I’m not good at English. :unamused:
Thank You. :smiley:


#4

I get the same result when running it myself. I suspect this is just a bug in NSSpeechSynthesizer.

Adam


#5

The behavior shown above (finishedSpeaking=0 even though speech synthesis was not stopped) only seems to happen when the voice is changed in the tableViewSelectionDidChange: method before the first speech synthesis takes place.

I commented out the code in tableViewSelectionDidChange: and ran the app, and got finishedSpeaking=1 every time. Once I re-enabled the code in tableViewSelectionDidChange: and it got called before the first click of the Speak button, finishedSpeaking was equal to 0 on the first pass.

It seems to have something to do with setting the voice of the synthesizer before the first string is spoken.