Poiché OS X 10.5, OS X è stato fornito con il bridge PyObjC, un bridge Python-Objective-C. Usa il framework BridgeSupport per mappare i framework Objective-C su Python. A differenza di MacRuby, PyObjC è un bridge classico: esiste un oggetto proxy sul lato python per ogni oggetto ObjC e viceversa. Il bridge è abbastanza semplice, tuttavia, ed è possibile scrivere intere app in PyObjC (Xcode ha un supporto PyObjC di base, e puoi scaricare i modelli di app e file per Xcode da PyObjC SVN al link precedente). Molti lo usano per utilità o per app-scripting/plug-in. Il sito per gli sviluppatori di Apple ha anche uno introduction per lo sviluppo di applicazioni Cocoa con Python tramite PyObjC, che è leggermente obsoleto, ma potrebbe essere una buona panoramica per voi.
Nel tuo caso, il seguente codice chiamerà [NSSpeechSynthesizer availableVoices]
:
from AppKit import NSSpeechSynthesizer
NSSpeechSynthesizer.availableVoices()
che restituisce
(
"com.apple.speech.synthesis.voice.Agnes",
"com.apple.speech.synthesis.voice.Albert",
"com.apple.speech.synthesis.voice.Alex",
"com.apple.speech.synthesis.voice.BadNews",
"com.apple.speech.synthesis.voice.Bahh",
"com.apple.speech.synthesis.voice.Bells",
"com.apple.speech.synthesis.voice.Boing",
"com.apple.speech.synthesis.voice.Bruce",
"com.apple.speech.synthesis.voice.Bubbles",
"com.apple.speech.synthesis.voice.Cellos",
"com.apple.speech.synthesis.voice.Deranged",
"com.apple.speech.synthesis.voice.Fred",
"com.apple.speech.synthesis.voice.GoodNews",
"com.apple.speech.synthesis.voice.Hysterical",
"com.apple.speech.synthesis.voice.Junior",
"com.apple.speech.synthesis.voice.Kathy",
"com.apple.speech.synthesis.voice.Organ",
"com.apple.speech.synthesis.voice.Princess",
"com.apple.speech.synthesis.voice.Ralph",
"com.apple.speech.synthesis.voice.Trinoids",
"com.apple.speech.synthesis.voice.Vicki",
"com.apple.speech.synthesis.voice.Victoria",
"com.apple.speech.synthesis.voice.Whisper",
"com.apple.speech.synthesis.voice.Zarvox"
)
(un NSCFArray ponte) sulla mia macchina SL.
+1 per esempio. –
Non è necessario importare il modulo objc, solo Foundation. –
Hah, hai ragione. Aggiornerò il mio esempio – Benno