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.
- Kotlin
- Java
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.
}
})
import ai.pleos.playground.tts.constant.ErrorType;
import ai.pleos.playground.tts.listener.OnInitializeListener;
textToSpeech.initialize(new OnInitializeListener() {
@Override
public void onSuccess() {
// The TextToSpeech API is now available.
}
@Override
public void 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.
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.
- Kotlin
- Java
override fun onDestroy() {
textToSpeech.removeEventListener(eventListener)
textToSpeech.release()
super.onDestroy()
}
@Override
protected void onDestroy() {
textToSpeech.removeEventListener(eventListener);
textToSpeech.release();
super.onDestroy();
}
To use the SDK again after release(), create a new instance and repeat the initialization process.