AVSpeechSynthesis
AVSpeechSynthesis
WWDC 2018
AVSpeechSynthesis
- API for computer synthesized speech
- Uses
- Announcements
- Non-sighted interfaces
- Education apps
- Many more… - Example — Audio updates during a workout
AVSpeechSynthesis and Accessibility
- Powerful tool for helping many users
- Congnitive
- Speech vocalization
- Non-sighted - Not a replacement for VoiceOver
- Speech can overlap with VoiceOver’s
- Won’t be available to Braille devices
- Make your app accessible instead usingUIAccessibility
Basics
- Create
AVSpeechSynthesizer
2. Ensure it’s retained until speech is done ⚠️
( Speech will be cancelled in the synthesizer is deallocated )
3. Create an utterance
4. Dispatch to synthesizer
AVSpeechSynthesis and Audio Sessions
AVAudioSession
automatically activated onspeak()
- To mix with other audio, use
- To duck other audio, use
Callbacks
- Delegate methods inform about the life cycle of an utterance
AVSpeechSynthesizerDelegate
defines optional methods
- Speech started
- Speech finished
- Character range will be spoken
- Speech paused
- Speech continued
Choosing the Right Voice
- Built in voices (1 for each supported language)
- Siri voices not available through API
- Users can download ⏬ higher quality voices
- Select with an identifier or a language
- Selecting by language will select the users default voice
Speech Rate
- Controls the rate of speech [ 0 ~ 1.0 ]
- Speaking Rate is scaled from ≅ 0x ➜ 1x with values [ 0, 0.5 ]
- Speaking Rate is scaled from 1x ➜ 4x with values [ 0.5, 1 ]
Pitch and Volume
Set properties on AVSpeechUtterance
- Pitch [ 0 ~ 1.0 ]
- Volume [ 0 ~ 1.0 ]
Attributed Strings
- Customize behavior of generated speech with attributes
- IPA Notation
- International Phonetic Alphabet
- Uses — Specialized names, proper nouns, business names…
- Available — en-US, en-AU, en-GB, de-DE, es-ES, es-MX, fr-CA, fr-FR, it-IT, ja-JP
- Example — iPhone = ˈa͡ɪ.ˈfo͡ʊn
IPA Notation
- How do you generate IPA notation?
- Settings > General > Accessibility > Speech > Pronunciations
- Use attributed string API with IPA pronunciation