Last active
February 11, 2019 06:48
-
-
Save myrickchow32/b75f12b0c83426596e468084057a8cc9 to your computer and use it in GitHub Desktop.
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 AVFoundation | |
| let avSpeechSynthesizer = AVSpeechSynthesizer() | |
| avSpeechSynthesizer.delegate = self | |
| // Session 1 --- AVSpeechUtterance: 7 Parameters of synthesized speech | |
| let utterance = AVSpeechUtterance(string: "Hello world") | |
| utterance.voice = ... | |
| utterance.rate = ... | |
| utterance.pitchMultiplier = ... | |
| utterance.volume = ... | |
| utterance.preUtteranceDelay = ... | |
| utterance.postUtteranceDelay = ... | |
| // Session 2 --- AVSpeechSynthesizer: 4 Speech operations | |
| avSpeechSynthesizer.speak(utterance) // Start speech | |
| avSpeechSynthesizer.pauseSpeaking(at: .immediate) // Pause even in the middle of a word | |
| avSpeechSynthesizer.pauseSpeaking(at: .word) // Pause after the current word has been voiced out completely | |
| avSpeechSynthesizer.stopSpeaking(at: .immediate) // Stop --- Similar to the `pauseSpeaking(at: .immediate)` | |
| avSpeechSynthesizer.stopSpeaking(at: .word) // Stop --- Similar to the `pauseSpeaking(at: .word)` | |
| avSpeechSynthesizer.continueSpeaking() // Resume a paused speech | |
| // Session 3 --- AVSpeechSynthesizerDelegate: 6 Speech callbacks | |
| extension FooViewController: AVSpeechSynthesizerDelegate { | |
| func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didStart utterance: AVSpeechUtterance) { } | |
| func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didFinish utterance: AVSpeechUtterance) { } | |
| func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didPause utterance: AVSpeechUtterance) { } | |
| func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didContinue utterance: AVSpeechUtterance) {} | |
| func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, didCancel utterance: AVSpeechUtterance) { } | |
| func speechSynthesizer(_ synthesizer: AVSpeechSynthesizer, willSpeakRangeOfSpeechString characterRange: NSRange, utterance: AVSpeechUtterance) { } | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment