IviTextToSpeech

class IviTextToSpeech

Synthesizes speech from text (TTS) for immediate playback.

Note: Due to engine initialization after creating this object, any speak calls can only be made once available has been set to 'true'.

Currently, IviTextToSpeech abandons focus when the current utterance ID matches the one of the last TextToSpeech.speak operation and the last TTS operation has finished. Since it is possible to play audio from different Android apps, it is required to check whether the audio focus is granted or not:

Note: When speaking is 'true', any speak action will be queued inside the speech engine.

When you are done using the IviTextToSpeech instance, call the shutdown method to release the native resources used by the IviTextToSpeech engine.

Types

Link copied to clipboard
object Companion
Link copied to clipboard
enum ResultStatus : Enum<IviTextToSpeech.ResultStatus>

The result of a TTS operation.

Properties

Link copied to clipboard
val available: LiveData<Boolean>

This is set to true when the speech engine is initialized. Only after this is set to true can the object be used to synthesise speech.

Link copied to clipboard
val speaking: LiveData<Boolean>

This is only true when the text-to-speech engine is currently playing an utterance.

Functions

Link copied to clipboard
suspend fun coSpeak(text: String): IviTextToSpeech.ResultStatus

Plays the specified text using text-to-speech and returns the asynchronous job. If the job is canceled, the utterance will be stopped.

Link copied to clipboard
fun shutdown()

Releases the resources used by the TextToSpeech engine. It is good practice for instance to call this method in the onDestroy() method of an Activity so the TextToSpeech engine can be stopped in a clean state.

Link copied to clipboard
fun speakAsync(text: String, resultCallback: (IviTextToSpeech.ResultStatus) -> Unit)

Plays the specified text asynchronously using text-to-speech. If any other utterance that was initiated by the same object is running, it will be stopped.

Link copied to clipboard
fun stopSpeaking()

Stops playing the current utterance.