Website Links

Friday 11 December 2015

Swift - Text to speech

  1. Add the following line to the class you want to use text to speech in "import AVFoundation"
  2. Create a speech synthesizer: let speechSynthesizer = AVSpeechSynthesizer()
  3. Create a speech utterance: let speechUtterance = AVSpeechUtterance(string: "Hello world!")
  4. 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.
  5. Use the speech synthesizer to speak the utterance: speechSynthesizer.speakUtterance(speechUtterance)

No comments:

Post a Comment