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 transitionAnimation(view: UIView, animationOptions: UIView.AnimationOptions, isReset: Bool) { | |
| // Combine transition annimation option with other animation options | |
| let combinedAnimationOptions: UIView.AnimationOptions = [animationOptions, .allowUserInteraction, .autoreverse, .repeat] | |
| UIView.transition(with: view, duration: durationOfAnimationInSecond, options: combinedAnimationOptions, animations: { | |
| view.backgroundColor = UIColor.init(named: isReset ? "darkGreen" : "darkRed") | |
| }, completion: nil) | |
| } |
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 Foundation | |
| import AVFoundation | |
| class VoiceUtils { | |
| static var avSpeechSynthesizer = AVSpeechSynthesizer() | |
| static func textToSpeech(text: String, delegate: AVSpeechSynthesizerDelegate?) { | |
| /* | |
| Support langauges: |
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() |
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 utterance = 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
| let speechVoices = AVSpeechSynthesisVoice.speechVoices() | |
| speechVoices.forEach { (voice) in | |
| print("**********************************") | |
| print("Voice identifier: \(voice.identifier)") | |
| print("Voice language: \(voice.language)") | |
| print("Voice name: \(voice.name)") | |
| print("Voice quality: \(voice.quality.rawValue)") // Compact: 1 ; Enhanced: 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
| let utterance = AVSpeechUtterance(string: "Hello world") | |
| // Method 1: Directly by identifier | |
| utterance.voice = AVSpeechSynthesisVoice(identifier: "com.apple.ttsbundle.Karen-compact") | |
| // Method 2: By langauge code | |
| utterance.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
| let utterance = AVSpeechUtterance(string: "Hello world") | |
| utterance.volume = 0.5 // Range: 0.0 - 1.0 ; A relative volume to the device volume |
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
| /* | |
| Range: 0.0 - 1.0 | |
| AVSpeechUtteranceMinimumSpeechRate: 0.0 | |
| AVSpeechUtteranceMaximumSpeechRate: 1.0 | |
| AVSpeechUtteranceDefaultSpeechRate: 0.5 | |
| */ | |
| let utterance = AVSpeechUtterance(string: "Hello world") | |
| utterance.rate = 0.5 |
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
| /* | |
| Pitch multiplier range: 0.5 to 2.0 | |
| Default value: 1.0 | |
| */ | |
| let utterance = AVSpeechUtterance(string: "Hello world") | |
| utterance.pitchMultiplier = 1.0 |
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 = ... |