---
title: "#194: Synthesizing Speech with AVSpeechUtterance 👄"
url: https://littlebitesofcocoa.com/194-synthesizing-speech-with-avspeechutterance
author: Jake Marsh
published: 2016-02-18
topics: ["Audio","AVFoundation"]
description: "Ever since 1983 when Matthew Broderick's IMSAI 8080 began speaking out loud, we've dreamed of computers that can have conversations with us."
---

# #194: Synthesizing Speech with AVSpeechUtterance 👄

By Jake Marsh, February 18, 2016. HTML: https://littlebitesofcocoa.com/194-synthesizing-speech-with-avspeechutterance

Ever since [1983](https://en.wikipedia.org/wiki/WarGames) when Matthew Broderick's [IMSAI 8080](https://en.wikipedia.org/wiki/IMSAI_8080) began speaking out loud, we've dreamed of computers that can have conversations with us.

In **iOS 9**, **Apple** added the ability to synthesize speech using the high-quality _'Alex'_ voice. Sadly it's only available on US devices for now, but that's sure to change. Let's try it out:

``` swift
guard let voice = AVSpeechSynthesisVoice(identifier: AVSpeechSynthesisVoiceIdentifierAlex) else { return }

let synth = AVSpeechSynthesizer()
synth.delegate = self

let utter = AVSpeechUtterance(string: "Would you like to play a game?")
utter.voice = voice

synth.speakUtterance(utter)
```

We start by making sure _'Alex'_ is available, then we make a new **synthesizer**. Next, we create an **AVSpeechUtterance**, and set it's **voice**. Then, we simply tell the **synthesizer** to speak! Very cool.

Even cooler, we can implement one of the optional functions of **AVSpeechSynthesizerDelegate** to get live progress callbacks as each word is spoken. Neat!

``` swift
func speechSynthesizer(synthesizer: AVSpeechSynthesizer, willSpeakRangeOfSpeechString characterRange: NSRange, utterance: AVSpeechUtterance) {
  print(characterRange)
}
```
