[Pythonmac-SIG] newbie questions about Mac APIs in Python
Joe Strout
joe at strout.net
Wed Oct 15 00:24:01 CEST 2008
On Oct 14, 2008, at 4:06 PM, Joe Strout wrote:
> Poking around in Foundation, sure enough, NSSpeechSynthesizer isn't
> there. A lot of other stuff is, like NSError, though. Where should
> NSSpeechSynthesizer be imported from, and why don't I need any other
> imports in my PyObjC source file?
Sheesh, I really need to find an email client with a 5-minute outgoing
mail delay... somehow, pressing the "Send" key always seems to kick my
brain into gear.
In this case, I discovered the "Find Selected Text in Documentation"
contextual menu command in XCode, which led me to the
NSSpeechSynthesizer Class Reference, which points out that this is in
the AppKit framework. So, modifying my earlier attempt a bit...
>>> import AppKit
>>> synth = AppKit.NSSpeechSynthesizer.alloc().initWithVoice_(None)
>>> synth.startSpeakingString_(u"Hello world!")
True
...and it works! Certainly not as easy as "speak", but easy enough.
And in its own way, it's very cool that you can read the Apple docs
for any (?) Cocoa class and just use it as-is from Python.
Man, it's good to be back!
Cheers,
- Joe
--
Joe Strout
joe at strout.net
Words of wisdom from Helen Philpot:
<http://margaretandhelen.wordpress.com/2008/10/07/maverick-my-ass/>
More information about the Pythonmac-SIG
mailing list