Initialization
After creating a TextToSpeech object, you must call initialize() to use the API. Once you finish using the SDK, call release() to release connections and internal resources.
Initialize the SDK
If you need the initialization result, pass OnInitializeListener.
- Kotlin
- Java
import ai.pleos.playground.tts.listener.OnInitializeListener
import ai.pleos.playground.tts.constant.ErrorType
textToSpeech.initialize(object : OnInitializeListener {
override fun onSuccess() {
// You can use the TextToSpeech API.
}
override fun onFailure(errorType: ErrorType) {
// Handle initialization failures.
}
})
import ai.pleos.playground.tts.constant.ErrorType;
import ai.pleos.playground.tts.listener.OnInitializeListener;
textToSpeech.initialize(new OnInitializeListener() {
@Override
public void onSuccess() {
// You can use the TextToSpeech API.
}
@Override
public void onFailure(ErrorType errorType) {
// Handle initialization failures.
}
});
If a result callback is not needed, you can call it without arguments.
textToSpeech.initialize()
Release the SDK
Call this when you no longer need to use the SDK. It is recommended to release registered event listeners before calling release().
note
Reuse the TextToSpeech object according to the lifecycle of the component using it. When it is no longer needed or when the application is terminating, 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();
}
If you want to use the SDK again after release(), create a new object and perform the initialization procedure again.