// // SUSpeaker.m // SpeechTest // // Created by raf on Sun Jan 28 2001. // Copyright (c) 2000 Raphael Sebbe. All rights reserved. // #import "SUSpeaker.h" #include #include void MySpeechDoneCallback(SpeechChannel chan,SInt32 refCon); void MySpeechWordCallback (SpeechChannel chan, SInt32 refCon, UInt32 wordPos, UInt16 wordLen); @interface SUSpeaker (Private) -(void) setCallbacks; -(NSPort*) port; -(void) setReserved1:(unsigned int)r; -(void) setReserved2:(unsigned int)r; -(BOOL) usesPort; -(void) handleMessage:(unsigned)msgid; @end @implementation SUSpeaker /*"Returns the voice names in the same order as expected by setVoice:."*/ +(NSArray*) voiceNames { NSMutableArray *voices = [NSMutableArray arrayWithCapacity:0]; short voiceCount; OSErr error = noErr; int voiceIndex; error = CountVoices(&voiceCount); if(error != noErr) return voices; //NSLog(@"hello : %d", voiceCount); for(voiceIndex=0; voiceIndex= 0 && _reserved2 >= 0) [_delegate willSpeakWord:self at:_reserved1 length:_reserved2]; else [_delegate willSpeakWord:self at:0 length:0]; } } else if(msgid == 8) { if([_delegate respondsToSelector:@selector(didFinishSpeaking:)]) { [_delegate didFinishSpeaking:self]; } } } //--- NSPort delegate --- - (void)handlePortMessage:(NSPortMessage *)portMessage { int msg = [portMessage msgid]; [self handleMessage:msg]; } @end void MySpeechDoneCallback(SpeechChannel chan,SInt32 refCon) { SUSpeaker *speaker = (SUSpeaker*)refCon; unsigned msg = 8; //NSLog(@"Speech Done"); if([speaker isKindOfClass:[SUSpeaker class]]) { if([speaker usesPort]) { NSPortMessage *message = [[NSPortMessage alloc] initWithSendPort:[speaker port] receivePort:[speaker port] components:nil]; [message setMsgid:msg]; [message sendBeforeDate:nil]; [message release]; } else { // short-circuit port [speaker handleMessage:msg]; } } } void MySpeechWordCallback(SpeechChannel chan, SInt32 refCon, UInt32 wordPos,UInt16 wordLen) { SUSpeaker *speaker = (SUSpeaker*)refCon; unsigned msg = 5; //pid_t pid = getpid(); //pthread_t t = pthread_self(); //NSLog(@"pid : %d", t); //NSLog(@"Word Done"); //while(1); if([speaker isKindOfClass:[SUSpeaker class]]) { [speaker setReserved1:wordPos]; [speaker setReserved2:wordLen]; if([speaker usesPort]) { NSPortMessage *message = [[NSPortMessage alloc] initWithSendPort:[speaker port] receivePort:[speaker port] components:nil]; [message setMsgid:msg]; [message sendBeforeDate:nil]; [message release]; } else { // short-circuit port [speaker handleMessage:msg]; } } }