Speech Synthesis

In iOS 7, Apple added text-to-speech capability, providing another handy tool for both accessibility and other tasks, including navigation and general fun. Use the AVSpeechSynthesizer and AVSpeechUtterance classes to speak any string you would like. This can be handy for long-form speech and provides a greater level of programmatic control than VoiceOver, including voice selection, pitch, rate, and timing. In addition, this functionality is available even when the user is not utilizing Accessibility.

Listing 15-2 demonstrates the utterance of a simple string with the added twist of randomizing the voice from all currently available English-speaking voices. You can easily change this to other languages and locales. Use AVSpeechSynthesisVoice ...

Get The Core iOS Developer’s Cookbook, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.