Re: speechSynthesizer willSpeakWord trouble
Re: speechSynthesizer willSpeakWord trouble
- Subject: Re: speechSynthesizer willSpeakWord trouble
- From: Ricky Sharp <email@hidden>
- Date: Fri, 6 Jul 2007 19:34:57 -0500
On Jul 6, 2007, at 7:13 PM, Ricky Sharp wrote:
On Jul 6, 2007, at 5:22 PM, Paul Bruneau wrote:
Hi everyone-
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}
The range is coming through OK, but no matter what I have tried,
the substring I am trying to get above) always comes out (null). I
have tried just putting myString (without the substring part) into
the log, but it is also (null).
Here is my init method for my controller:
-(id)init
{
[super init];
NSLog(@"init");
speechSynth = [[NSSpeechSynthesizer alloc] initWithVoice:nil];
[speechSynth setDelegate:self];
return self;
}
Any ideas for newbie me? Thank you.
Wow, that appears to be a bug. I just wrote a test app (ran under
10.4.10/Intel) and that delegate method always receives nil for the
string param. The two other delegates do work correctly (to
include speechSynthesizer:willSpeakPhoneme:)
You may want to take this question to the speech-dev list.
Extremely light traffic, but speech engineers do eventually read
the posts. Also, I'd file a bug.
If you absolutely need this functionality, you'll probably have to
step down to the Carbon speech APIs. I've had to do this myself
(for other reasons) since the Cocoa APIs do not expose the entire
feature set that Carbon gives you.
I just looked at Apple's sample speech code. The
NSSpeechSynthesizerExample implements that delegate, but its string
param is always nil too. They kind of cheated though in that they
set up an ivar to hold the text field. They then set the field's
selection based upon the incoming range. They never use the string
param.
I suppose a workaround is to cache off a copy of the string that
you've fed to the speech synthesizer and as long as your delegate has
access to that string, you can then extract the actual word being
spoken.
The other example (CocoaSpeechSynthesisExample) uses the low-level C-
based speech APIs.
___________________________________________________________
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