This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let avSpeechSynthesizer = AVSpeechSynthesizer() | |
| ... | |
| avSpeechSynthesizer.continueSpeaking() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let avSpeechSynthesizer = AVSpeechSynthesizer() | |
| ... | |
| // Option: Pause immediately at that pronunciation | |
| avSpeechSynthesizer.pauseSpeaking(at: .immediate) | |
| // Option: Pause at the end of the pronunciation of the whole word | |
| avSpeechSynthesizer.pauseSpeaking(at: .word) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| let avSpeechSynthesizer = AVSpeechSynthesizer() | |
| avSpeechSynthesizer.speak(AVSpeechUtterance(string: "Hello world")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| No compile and runtime error | |
| Outcome: only "First AVSpeechSynthesizer" is outputed | |
| */ | |
| let firstAvSpeechSynthesizer = AVSpeechSynthesizer() | |
| firstAvSpeechSynthesizer.speak(getUtterance("First AVSpeechSynthesizer")) | |
| let secondAvSpeechSynthesizer = AVSpeechSynthesizer() | |
| secondAvSpeechSynthesizer.speak(getUtterance("Second AVSpeechSynthesizer")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func getUtterance(_ speechString: String) -> AVSpeechutterance { | |
| let utterance = AVSpeechUtterance(string: speechString) | |
| utterance.voice = ... | |
| utterance.rate = ... | |
| utterance.pitchMultiplier = ... | |
| utterance.volume = ... | |
| utterance.preUtteranceDelay = ... | |
| utterance.postUtteranceDelay = ... | |
| return utterance | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import UIKit | |
| // Step 1: Import AVFoundation library | |
| import AVFoundation | |
| class AVFoundataionDemoViewController: BaseViewController { | |
| var avSpeechSynthesizer: AVSpeechSynthesizer! | |
| @IBAction func startSpeechAction(_ sender: Any) { | |
| // Step 4: Stop any existing speech, else it will not start !!! | |
| avSpeechSynthesizer.stopSpeaking(at: .immediate) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| ********************************** | |
| Voice identifier: com.apple.ttsbundle.Maged-compact | |
| Voice language: ar-SA | |
| Voice name: Maged | |
| Voice quality: 1 | |
| ********************************** | |
| Voice identifier: com.apple.ttsbundle.Zuzana-compact | |
| Voice language: cs-CZ | |
| Voice name: Zuzana |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func getUtteranceWithDelay(preUtteranceDelayInSecond: Int, postUtteranceDelayInSecond: Int) -> AVSpeechUtterance { | |
| let utterance = AVSpeechUtterance(string: "Hello world") | |
| utterance.preUtteranceDelay = TimeInterval.init(exactly: preUtteranceDelayInSecond)! | |
| utterance.postUtteranceDelay = TimeInterval.init(exactly: postUtteranceDelayInSecond)! | |
| return utterance | |
| } | |
| let avSpeechSynthesizer = AVSpeechSynthesizer() | |
| avSpeechSynthesizer.speak(getUtteranceWithDelay(preUtteranceDelayInSecond: 1, postUtteranceDelayInSecond: 2)) | |
| avSpeechSynthesizer.speak(getUtteranceWithDelay(preUtteranceDelayInSecond: 1, postUtteranceDelayInSecond: 2)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Three possible outcomes: | |
| 1. The user selected accent in "en-AU" category | |
| 2. iOS default accent in "en-AU" category | |
| 2.1 Compact | |
| 2.2 Enhanced (if user has downloaded) | |
| */ | |
| let voice = AVSpeechSynthesisVoice(language: "en-AU") | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Utterance contains with both English and Traditional Chinese words | |
| let utterance = AVSpeechUtterance(string: "Hong Kong(香港)is in Asia.") | |
| utterance.voice = AVSpeechSynthesisVoice(language: "zh-HK") | |
| let avSpeechSynthesizer = AVSpeechSynthesizer() | |
| avSpeechSynthesizer.speak(utterance) |