TextToSpeech
public protocol TextToSpeech : AnyObject
Manages the TTS (Text-To-Speech) engine. Provides functionality for changing the engine, setting the language, playing messages, stopping playback, and adjusting volume.
The TextToSpeech protocol is essential for applications that require text-to-speech capabilities.
It enables dynamic replacement of the TTS engine, adjustment of the spoken language, prioritization of messages, playback control, and speech volume configuration.
Important
This is a Public Preview API. It may be changed or removed at any time.-
Replaces the current instance of the
TextToSpeechEnginewith a new one.It allows for runtime replacement of the TTS engine, enabling flexibility and customization. Ensure the new engine is properly configured before passing it to this method.
Declaration
Swift
func changeTTsEngine(to ttsEngine: TextToSpeechEngine)Parameters
ttsEngineThe new text-to-speech engine to be used. Must conform to the
TextToSpeechEngineprotocol. -
Updates the language of the
TextToSpeechEngineto a specified locale.This method changes the locale used by the TTS engine, facilitating support for multiple languages. Ensure the specified locale is supported by the TTS engine to prevent errors.
Throws
TextToSpeechEngineError.unavailableLocaleInVoicesif the TTS engine does not support the specifiedlocale.Declaration
Swift
func changeLanguage(locale: Locale) throwsParameters
localeThe new locale to set. This should be a locale supported by the TTS engine.
-
Play the message.
Plays a specified message using the TTS engine. Messages can be prioritized and have timeouts.
Declaration
Swift
func play(message: TTSMessage, priority: TTSMessagePriority)Parameters
messageThe message to play. This should be a
TTSMessageobject containing the text to be spoken.priorityThe priority of the message with a timeout. This determines the order and urgency of message playback.
-
Stop playing the voice message.
It stops any ongoing message playback, allowing for interruption of speech.
Declaration
Swift
func stop() -
Set the speech volume.
It adjusts the speech volume, allowing for dynamic volume changes. Ensure the volume level is within the acceptable range before setting it.
Declaration
Swift
func setVolume(_ volume: SpeechVolume)Parameters
volumeThe volume level to set. This should be a
SpeechVolumevalue representing the desired volume.
TomTom SDK for iOS (0.71.1)
TextToSpeech