iOS

AVSpeechSynthesizer

Syntax#

  • AVSpeechSynthesizer() // Creates a speech synthesiser
  • speaker.speakUtterance(speech) // Converts the text to speech

Parameters#

Parameter Details
speaker AVSpeechSynthesizer object
speech AVSpeechUtterance object
## Creating a basic text to speech
Use the speakUtterance: method of AVSpeechSynthesizer to convert text to speech. You need to pass an AVSpeechUtterance object to this method, which contains the text that you want to be spoken.

Objective C

AVSpeechSynthesizer *speaker = [[AVSpeechSynthesizer alloc] init];
AVSpeechUtterance *speech    = [AVSpeechUtterance speechUtteranceWithString:@"Hello World"];
[speaker speakUtterance:speech];

Swift

let speaker = AVSpeechSynthesizer()
let speech = AVSpeechUtterance(string: "Hello World")
speaker.speakUtterance(speech)

This modified text is an extract of the original Stack Overflow Documentation created by the contributors and released under CC BY-SA 3.0 This website is not affiliated with Stack Overflow