- Add the following line to the class you want to use text to speech in "import AVFoundation"
- Create a speech synthesizer: let speechSynthesizer = AVSpeechSynthesizer()
- Create a speech utterance: let speechUtterance = AVSpeechUtterance(string: "Hello world!")
- Apply your desired properties to the speech utterance, e.g:
- speechUtterance.rate : how fast or slow the string will be spoken, acceptable values are between 0.0 and 1.0
- speechUtterance.volume : how loudly the string will be spoken, acceptable values are between 0.0 and 1.0
- More properties can be found on the AVSpeechUtterance reference page.
- Use the speech synthesizer to speak the utterance: speechSynthesizer.speakUtterance(speechUtterance)
Friday, 11 December 2015
Swift - Text to speech
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment