Hi all,

I am trying to write an app that has a hard-coded NSString, formatted like this:

@"Alex: This is a test.\nBruce: One two.\nFred: This is another test."

The idea is that the lines in the text are spoken using the indicated voice. In the example above, line one is Alex, line two is Bruce, and line three is Fred.

I'm puzzled, however, because what ends up happening is that only the last line ("This is another test") is spoken. Furthermore, the voice used is the first one in the list (Alex). I've tested this with multiple last lines and voices.

So, I set breakpoints in my code:

(IBAction)speakPlay:(id)sender
{
   NSLog(@"Starting to speak play");
[isSpeakingField setStringValue:@"Speaking"]; for (NSString *line in separatedPlay) { // set the speaker for this line NSUInteger locationOfFirstColonInLine = [line rangeOfString:@":"].location; NSString *characterForLine = [line substringToIndex:locationOfFirstColonInLine];
       [speechSynthesizer setVoice:
[NSString stringWithFormat:@"com.apple.speech.synthesis.voice.%@", characterForLine]]; NSString *partOfLineToSpeak = [line substringFromIndex:(locationOfFirstColonInLine + 2)]; // speak the part of the line after the character
       [speechSynthesizer startSpeakingString:partOfLineToSpeak];
   }
}


When I use the debugger:

- The voice (Alex, in this case) is correctly recognized from the text.
- The speech synthesizer is set to the correct voice.
- "partOfLineToSpeak" is set correctly (to "This is a test.")
- When I get to the "start speaking" command, I get two long (wrapped to several lines each) lines of blather about what I think is the audio driver, but no voice. (Although I tested this on another app I wrote to synthesize a line the user types in, and the same thing happens: blather, but no voice when using gdb.)

So I'm stumped. Why is the wrong line spoken (w/o the debugger), but, with the debugger, the correct line is used?

Thanks,
Daniel

P.S. my init code is below in case you want to refer to that.

- (id)init {
   [super init];
play = @"Alex: This is a test.\nBruce: One two.\nFred: This is another test."; separatedPlay = (NSMutableArray *) [play componentsSeparatedByString:@"\n"]; speechSynthesizer = [[NSSpeechSynthesizer alloc] initWithVoice:nil];
   [speechSynthesizer setDelegate:self];
return self;
}
-
_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to