Is there a way to tell when SpeechRecognizer.cancel() processing has completed successfully?

44 Views Asked by At

Once SpeechRecognizer.cancel() is invoked, is there a way to tell that it has been completely processed, to the point of not interpreting any sound an microphone and not invoking any of its ReognitionListener callbacks?

More specifically, when SpeechRecognizer.cancel() is invoked, all it does is place a MSG_CANCEL in the main thread's queue:

@MainThread
public void cancel() {
    checkIsCalledFromMainThread();
    putMessage(Message.obtain(mHandler, MSG_CANCEL));
}

Then, at some point (no immediacy guarantee), the message is handled:

private Handler mHandler = new Handler(Looper.getMainLooper()) {

    @Override
    public void handleMessage(Message msg) {
        switch (msg.what) {
            case MSG_START:
                handleStartListening((Intent) msg.obj);
                break;
            case MSG_STOP:
                handleStopMessage();
                break;
            case MSG_CANCEL:
                handleCancelMessage();
                break;

by further relaying it to the IRecognitionService service:

private void handleCancelMessage() {
    if (!checkOpenConnection()) {
        return;
    }
    try {
        mService.cancel(mListener, /*isShutdown*/ false);
        if (DBG) Log.d(TAG, "service cancel command succeeded");
    } catch (final RemoteException e) {
        Log.e(TAG, "cancel() failed", e);
        mListener.onError(ERROR_CLIENT);
    }
}

But I have not been able to find any callback or listener that notifies the app when the IRecognitionService has completed successfully.

Any idea for a way to tell when SpeechRecognizer.cancel() processing has completed successfully?

0

There are 0 best solutions below