0

Do we have any ways to get sound from text?

For example, we have:

let str = "Hello English" .

I want to get sound system from that text.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
Ravy Chheng
  • 153
  • 1
  • 2
  • 7
  • 1
    look into AVSpeechSynthesizer, there is a tutorial at AppCoda http://www.appcoda.com/text-to-speech-ios-tutorial/ – JustinM Mar 29 '17 at 14:17
  • 1
    http://stackoverflow.com/questions/21623251/how-to-convert-string-to-audio-sound-file-in-ios-cocos2d and http://stackoverflow.com/questions/13860091/ios-text-to-speech-conversion – MAhipal Singh Mar 29 '17 at 14:17
  • Google : "Text To speech" – Muhammad Adnan Mar 29 '17 at 14:39
  • import AVFoundation func playSound(str: String){ let speechSynthesizer = AVSpeechSynthesizer() let speechUtterance = AVSpeechUtterance(string: str) speechSynthesizer.speak(speechUtterance) } – Ravy Chheng Mar 29 '17 at 15:08

1 Answers1

1

As Ravy Chheng answered, this uses the built-in AVFoundation library to initialize basic text-to speak function. For more information, check out the documentation by Apple: https://developer.apple.com/reference/avfoundation/avspeechsynthesizer

import AVFoundation

func playSound(str: String) {
    let speechSynthesizer = AVSpeechSynthesizer()
    let speechUtterance = AVSpeechUtterance(string: str)
    speechSynthesizer.speak(speechUtterance)
}
Tamás Sengel
  • 55,884
  • 29
  • 169
  • 223