目录

class info
com.huawei.hms.mlsdk.asr.MLAsrListener
Receives data and event notifications from MLAsrRecognizer when an ASR event occurs.

Public Method Summary

Return typeMethod name
voidonError(int error, String errorMessage)
voidonRecognizingResults(Bundle recognizingResults)
voidonResults(Bundle results)
voidonStartListening()
voidonStartingOfSpeech()
voidonState(int state, Bundle params)
voidonVoiceDataReceived(byte[] data,float energy, Bundle params)

Public Methods

Method
public void onError(int error, String errorMessage)
Called when a network error or recognition error occurs.

Parameters

Parameter nameParameter desc
errorResult code. For details about the result codes, please refer to MLAsrConstants.ERR_NO_NETWORKERR_NO_UNDERSTANDERR_SERVICE_UNAVAILABLE
errorMessageError message.
Method
public void onRecognizingResults(Bundle recognizingResults)
When the speech recognition mode is set to MLAsrConstants.FEATURE_WORDFLUX, the speech recognizer continuously returns the speech recognition result through this API.

Parameters

Parameter nameParameter desc
recognizingResultsResult returned during speech recognition.Currently, Bundle carries the recognized text information, which is stored in the value with MLAsrRecognizer.RESULTS_RECOGNIZING as the key in the string type.
Method
public void onResults(Bundle results)
Called when the speech recognition result is received from the speech recognizer.

Parameters

Parameter nameParameter desc
resultsSpeech recognition result.Currently, Bundle carries the recognized text information, which is stored in the value with MLAsrRecognizer.RESULTS_RECOGNIZED as the key in the string type.
Method
public void onStartListening()
Called when the recorder starts to receive speech.
Method
public void onStartingOfSpeech()
Called when a user starts to speak, that is, the speech recognizer detects that the user starts to speak.
Method
public void onState(int state, Bundle params)
Notifies the app status change.

Parameters

Parameter nameParameter desc
stateStatus code. For details, please refer to MLAsrConstants.
paramsReserved fields.
Method
public void onVoiceDataReceived(byte[] data,float energy, Bundle params)
Returns the original PCM stream and audio power to the user.

Parameters

Parameter nameParameter desc
dataPCM stream, with PCM mono, 16-bit depth, and 16 kHz audio sampling rate.
energyAudio power.
paramsReserved fields.