Skip to content

Instantly share code, notes, and snippets.

@hekt
Created November 3, 2014 05:08
Show Gist options
  • Save hekt/9523219adaa40b09cfcc to your computer and use it in GitHub Desktop.
Save hekt/9523219adaa40b09cfcc to your computer and use it in GitHub Desktop.
SpeakLine アプリケーションの Swift 版 (『MAC OS X COCOA プログラミング』第5章)
import Cocoa
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
@IBOutlet weak var window: NSWindow!
@IBOutlet weak var textField: NSTextField!
let speechSynth = NSSpeechSynthesizer(voice: nil)
@IBAction func stopIt(sender: AnyObject) {
NSLog("stopping")
speechSynth.stopSpeaking()
}
@IBAction func sayIt(sender: AnyObject) {
let string = textField.stringValue
if countElements(string) == 0 {
NSLog("String from %@ is of zero-length", textField)
return
}
speechSynth.startSpeakingString(string)
NSLog("Have started to say: %@", string)
}
func applicationDidFinishLaunching(aNotification: NSNotification) {
NSLog("init")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment