As a hobbyist Applescripter, I’m taking my first steps into ApplescriptObjC in X code.
I am not working on any specific project, but am doing various little exercises in an attempt
to learn the ApplescriptObjC language, and also the Cocoa Framework’s classes and objects.
I’m getting error messages in the debug console concerning my calls to the NSSpeechSynthesizer
class, the errors are on the setDelegate: startSpeakingString: and stopSpeaking: methods in the
attached code, I know that I could use the say command in the Standard Additions to accomplish
this example, but that would defeat the object of learning the Cocoa Framework’s.
I have tried using the alloc()'s initWithVoice_() method in the startButton’s handler, and also in a
tell class “NSSpeechSynthesizer” of current application end tell block, but the unrecognised
selector sent to class error still appears in the debug console.
I have read through the documentation on the NSSpeechSynthesizer class, but I have not found
anything to solve my problem, although this is not an important project for me, solving it would
also possibly solve future problems on other Cocoa classes, where the solution may also not be
that obvious.
[code]script SpeaklineAppDelegate
property parent : class “NSObject”
property textField : missing value
property startButton : missing value
property stopButton : missing value
property speechSynth : class “NSSpeechSynthesizer” of current application
on run {}
initialize()
end run
on initialize()
speechSynth’s alloc()'s initWithVoice_(missing value)
speechSynth’s setDelegate_(me) --problem line of code Here–
return me
end initialize
on sayIt_(sender)
set speechText to textField’s stringValue() as string
if (length of speechText) is equal to 0 then
return
else
my stopButton’s setEnabled_(true)
my startButton’s setEnabled_(false)
speechSynth’s startSpeakingString_(textField’s stringValue()) --problem line of code Here–
end if
end sayIt_
on stopIt_(sender)
speechSynth’s stopSpeaking() --problem line of code Here–
end stopIt_
on speechSynthesizer_didFinishSpeaking_(speechSynth, complete)
my stopButton’s setEnabled_(false)
my startButton’s setEnabled_(true)
end speechSynthesizer_didFinishSpeaking_
on applicationWillFinishLaunching_(aNotification)
– Insert code here to initialize your application before any files are opened
end applicationWillFinishLaunching_
on applicationShouldTerminate_(sender)
– Insert code here to do any housekeeping before your application quits
return current application’s NSTerminateNow
end applicationShouldTerminate_
end script[/code]
Many Thanks if anyone can help.
Regards Mark