Skip to main content

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.

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.
}
})

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().

override fun onDestroy() {
speechToText.removeListener(resultListener)
speechToText.release()
super.onDestroy()
}

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