Re: [Pyobjc-dev] PyObjC speech
Brought to you by:
ronaldoussoren
From: Frederik De B. <fre...@pa...> - 2004-05-18 18:48:54
|
Hi, Thanks for your quick reply! I *did* in fact make that signature up. I was trying to go by the documentation of objc.selector, hoping that the values for argumentTypes were equal to those in the method signature. Turns out they weren't. I'm posting my correct example. Note that I'm running this from an appcontext already. (PythonIDE, and in the future, DrawBot) This one waits nicely for a speech item to finish before starting on the next one. Again, many thanks, Frederik ---------------- import objc from AppKit import * from Foundation import * class BabbleBox(NSObject): def init(self): self = super(BabbleBox, self).init() self.synth= NSSpeechSynthesizer.alloc().init() self.synth.setVoice_("com.apple.speech.synthesis.voice.Kathy") self.synth.setDelegate_(self) self.speechQueue = [] return self def voices(self): return self.synth.availableVoices() def speak(self, txt): if (self.synth.isSpeaking()): self.speechQueue.append(txt) else: self.synth.startSpeakingString_(txt) def speechSynthesizer_willSpeakWord_ofString_(self, synth, word, string): loc, length = word word = string[loc:loc+length] print "I will say: ", word speechSynthesizer_willSpeakWord_ofString_ = objc.selector(speechSynthesizer_willSpeakWord_ofString_, signature="v@:@{_NSRange=II}@") def speechSynthesizer_didFinishSpeaking_(self, synth, finishedSpeaking): if len(self.speechQueue) > 0: txt = self.speechQueue[0] del self.speechQueue[0] self.synth.startSpeakingString_(txt) speechSynthesizer_didFinishSpeaking_ = objc.selector(speechSynthesizer_didFinishSpeaking_, signature="v@:@B") b = BabbleBox.alloc().init() b.speak("How are you?") b.speak("I'm fine, thanks") |