November 2016
Intermediate to advanced
480 pages
14h 42m
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)
import Cocoa
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") } ...Read now
Unlock full access