• 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: speechSynthesizer willSpeakWord trouble
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: speechSynthesizer willSpeakWord trouble


  • Subject: Re: speechSynthesizer willSpeakWord trouble
  • From: Ricky Sharp <email@hidden>
  • Date: Fri, 6 Jul 2007 19:22:16 -0500

On Jul 6, 2007, at 6:16 PM, glenn andreas wrote:

On Jul 6, 2007, at 5:22 PM, Paul Bruneau wrote:

I am just messing around with some speech stuff (expanding on examples from Hillegass' book) and I just can't make the willSpeakWord delegate work right. Here is my method:

-(void)speechSynthesizer:(NSSpeechSynthesizer *)sender
willSpeakWord:(NSRange)characterRange
ofString:(NSString *)myString;
{
NSLog(@"Range: %@", NSStringFromRange(characterRange));
NSLog(@"Speaking: %@", [myString substringWithRange:characterRange]);
}


my output goes like this:

2007-07-06 18:07:03.463 SpeakLine[366] Range: {0, 5}
2007-07-06 18:07:03.463 SpeakLine[366] Speaking: (null)
2007-07-06 18:07:03.785 SpeakLine[366] Range: {6, 5}
2007-07-06 18:07:03.785 SpeakLine[366] Speaking: (null)
2007-07-06 18:07:04.236 SpeakLine[366] Range: {12, 6}

[snip]
Any ideas for newbie me? Thank you.

Does your object have an instance variable named "myString"? (whose name then hides the parameter "myString")?

The name of that parameter doesn't matter (in my test app, I left it as 'text' as shown in the docs for that delegate). Anyhow, delegate APIs are called by the speech synthesizer itself. For example:


// MyController is app's delegate
@interface MyController : NSObject
{
    NSSpeechSynthesizer* synth;
}
@end

@implementation MyController

- (void)speechSynthesizer:(NSSpeechSynthesizer *)sender didFinishSpeaking:(BOOL)success
{
// This delegate is called at the correct point in time (i.e. after speech completes)
NSLog (@"didFinishSpeaking %@", success ? @"YES" : @"NO");
}


- (void)speechSynthesizer:(NSSpeechSynthesizer *)sender willSpeakPhoneme:(short)phonemeOpcode
{
// This delegate is also called correctly
NSLog (@"willSpeakPhoneme %d", phonemeOpcode);
}


- (void)speechSynthesizer:(NSSpeechSynthesizer *)sender willSpeakWord: (NSRange)characterRange ofString:(NSString *)text
{
NSLog(@"Range: %@", NSStringFromRange(characterRange));
NSLog(@"Speaking: %@", [text substringWithRange:characterRange]); // text is always nil
}


- (void)applicationDidFinishLaunching:(NSNotification*)aNotification
{
    synth = [[NSSpeechSynthesizer alloc] initWithVoice:nil];
    [synth setDelegate:self];
    [synth startSpeakingString:@"Testing Speech Synthesizer"];
}

@end


Output (I'm limiting this to only the last word) is:

Range: {15, 11}
Speaking: (null)
willSpeakPhoneme 33
willSpeakPhoneme 8
<7 more opcodes snipped>
willSpeakPhoneme 32
willSpeakPhoneme 0
didFinishSpeaking YES

the "willSpeakWord" delegate should have been given strings of "Test", "Speech" and "Synthesizer".

___________________________________________________________
Ricky A. Sharp         mailto:email@hidden
Instant Interactive(tm)   http://www.instantinteractive.com

_______________________________________________

Cocoa-dev mailing list (email@hidden)

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:
This email sent to email@hidden


  • Follow-Ups:
    • Re: speechSynthesizer willSpeakWord trouble
      • From: Paul Bruneau <email@hidden>
References: 
 >Re: Cocoa and dead-code stripping (From: Scott Ribe <email@hidden>)
 >Re: Cocoa and dead-code stripping (From: Alastair Houghton <email@hidden>)
 >speechSynthesizer willSpeakWord trouble (From: Paul Bruneau <email@hidden>)
 >Re: speechSynthesizer willSpeakWord trouble (From: glenn andreas <email@hidden>)

  • Prev by Date: Re: speechSynthesizer willSpeakWord trouble
  • Next by Date: Re: speechSynthesizer willSpeakWord trouble
  • Previous by thread: Re: speechSynthesizer willSpeakWord trouble
  • Next by thread: Re: speechSynthesizer willSpeakWord trouble
  • Index(es):
    • Date
    • Thread