Initialization
After creating a SpeechToText instance, call initialize() before using its APIs. When you have finished using the SDK, call release() to release connections and internal resources.
Initialize the SDK
To receive the initialization result, pass an OnInitializeListener.
- Kotlin
- Java
import ai.pleos.playground.stt.constant.ErrorType
import ai.pleos.playground.stt.listener.OnInitializeListener
speechToText.initialize(object : OnInitializeListener {
override fun onSuccess() {
// You can use the SpeechToText APIs.
}
override fun onFailure(errorType: ErrorType) {
// Handle the cause of initialization failure.
}
})
import ai.pleos.playground.stt.constant.ErrorType;
import ai.pleos.playground.stt.listener.OnInitializeListener;
speechToText.initialize(new OnInitializeListener() {
@Override
public void onSuccess() {
// You can use the SpeechToText APIs.
}
@Override
public void onFailure(ErrorType errorType) {
// Handle the cause of initialization failure.
}
});
If you do not need a result callback, call it without an argument.
speechToText.initialize()
Release the SDK
Reuse the SpeechToText instance according to the lifecycle of the component that uses it. When the instance is no longer needed or the application is shutting down, remove the registered result listener and call release().
- Kotlin
- Java
override fun onDestroy() {
speechToText.removeListener(resultListener)
speechToText.release()
super.onDestroy()
}
@Override
protected void onDestroy() {
speechToText.removeListener(resultListener);
speechToText.release();
super.onDestroy();
}
To use the SDK again after release(), create a new instance and repeat the initialization procedure.