December 2015
Intermediate to advanced
400 pages
13h 3m
English
Logging the text is nice, but the real goal of VocalTextEdit is that the computer will read your users’ text to them. Cocoa provides a class for synthesizing speech, suitably named NSSpeechSynthesizer. Begin by adding a property to your ViewController that is an instance of NSSpeechSynthesizer.
Listing 26.4 Adding an instance of NSSpeechSynthesizer (ViewController.swift)
class ViewController: NSViewController {
let speechSynthesizer = NSSpeechSynthesizer()
@IBOutlet var textView: NSTextView!
@IBAction func speakButtonClicked(sender: NSButton) {
print("I should speak \(textView.string)")
}
@IBAction func stopButtonClicked(sender: NSButton) {
print("The stop button was clicked")
}
}
The default ...
Read now
Unlock full access