Tuesday, January 13, 2015

AVSpeechSynthesizer - Text-to-speech function

import UIKit
import AVFoundation

class ViewController: UIViewController {
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mySynthesizer = AVSpeechSynthesizer()
        let myUtterence = AVSpeechUtterance(string: "Hello World. Testing 1 2 3.")
        myUtterence.rate = AVSpeechUtteranceMinimumSpeechRate
        myUtterence.voice = AVSpeechSynthesisVoice(language: "en-au")
        myUtterence.pitchMultiplier = 0.5 //between 0.5 and 2.0. Default is 1.0.
        mySynthesizer.speakUtterance(myUtterence)

    }

No comments:

Post a Comment