AVSpeechSynthesizer – iOS Text to Speech in iOS 7

By | September 25, 2013
texttospeechxcode

Apple added lots of new useful API’s in iOS 7, I am going to speak about one quickly today, AVSpeechSynthesizer.

In short, this is Text to Speech, a really simple way to have iOS read a piece of text out loud. There are a number of use cases for this, navigation, directions, visual impairments, introductions etc.

This framework is very easy to implement, the source code for this example is available on my GitHub .

Firstly you will need to include 2 Frameworks in your project (AudioToolbox.framework and AVFoundation.framework)

avfoundation

 

The simplest implementation of Text To Speech is only a few lines of code, in this example you could test this by adding the following code to your ViewDidLoad method, make sure that you have imported the AVFramework into your header file (#import <AVFoundation/AVFoundation.h>).

AVSpeechSynthesizer *synthesizer = [[AVSpeechSynthesizer alloc]init];
    AVSpeechUtterance *utterance = [AVSpeechUtterance speechUtteranceWithString:@"Some random text that you want to be spoken"];
    [utterance setRate:1.1f];
    [synthesizer speakUtterance:utterance];

Easy isn’t it? :)

Find the full source code on GitHub , this will show you how to read from a text-box and also to increase and decrease the speed at which the text is spoken.

AVSpeechSynthesizer

9 thoughts on “AVSpeechSynthesizer – iOS Text to Speech in iOS 7

    1. Jon Post author

      My pleasure, please let me know if there are any other tutorials you would like me to put together!

      Reply
  1. Andew Raynes

    Great tutorial. I wouldn’t mind a tutorial on using the camera to record within an app.

    Thanks

    Reply
  2. Andew Raynes

    Following from my previous comment it would also be interesting to see some edits/additions to the following application;

    > A settings area with both a male/female narrator
    > Own button/icon for the speak button
    > Perhaps different accents for narrators.

    Reply
  3. Young Yi

    Great tutorial!
    Would you tell a little bit how to apply this for the text stored in plist?

    Reply
    1. Jon Post author

      Hi,

      Yes this is very straight forward, do you have an example of the PLIST file that you are using?

      JF

      Reply

Leave a Reply to Jon Cancel reply