Skip to main content

Initialization

After creating a TextToSpeech instance, call initialize() before using other SDK APIs. When you have finished using the SDK, call release() to close connections and release internal resources.

Initialize the SDK​

Pass an OnInitializeListener when your app needs to receive the initialization result.

import ai.pleos.playground.tts.listener.OnInitializeListener
import ai.pleos.playground.tts.constant.ErrorType

textToSpeech.initialize(object : OnInitializeListener {
override fun onSuccess() {
// The TextToSpeech API is now available.
}

override fun onFailure(errorType: ErrorType) {
// Handle the cause of initialization failure.
}
})

If your app does not need a result callback, call the method without an argument.

textToSpeech.initialize()

Release the SDK​

Call release() when the SDK is no longer needed. We recommend removing registered event listeners before releasing the SDK.

tip

Reuse the TextToSpeech instance according to the lifecycle of the component that owns it. When the instance is no longer needed or the application is shutting down, call release() to release SDK resources.

override fun onDestroy() {
textToSpeech.removeEventListener(eventListener)
textToSpeech.release()
super.onDestroy()
}

To use the SDK again after release(), create a new instance and repeat the initialization process.