How to check if SpeechRecognizer is working?

I am trying to track the state SpeechRecognizer, for example:

private SpeechRecognizer mInternalSpeechRecognizer;
private boolean mIsRecording;

public void startRecording(Intent intent) {
 mIsRecording = true;
 // ...
 mInternalSpeechRecognizer.startListening(intent);
}

The problem with this approach is that saving a flag is mIsRecordingactually tough, for example. if there ERROR_NO_MATCHerror should be set to falseor not?
I feel that some devices stop recording, while others do not.

I do not see any method, for example SpeechRecognizer.isRecording(context), so I am wondering if there is a way to request through running services.

+4
source share
1 answer

RecognitionListener SpeechRecognizer. , startListening()!

:

mInternalSpeechRecognizer.setRecognitionListener(new RecognitionListener() {

    // Other methods implementation

    @Override
    public void onEndOfSpeech() {
        // Handle end of speech recognition
    }

    @Override
    public void onError(int error) {
        // Handle end of speech recognition and error
    }

    // Other methods implementation 
});

, mIsRecording, RecognitionListener. :

mIsRecording = false;

, mIsRecording = true . onReadyForSpeech(Bundle params), , .

, , , juste , :

// Other RecognitionListener methods implementation

@Override
public void onEndOfSpeech() {
    mIsRecording = false;
}

@Override
public void onError(int error) {
    mIsRecording = false;
    // Print error
}

@Override
void onReadyForSpeech (Bundle params) {
    mIsRecording = true;
}

public void startRecording(Intent intent) {
    // ...
    mInternalSpeechRecognizer.setRecognitionListener(this);
    mInternalSpeechRecognizer.startListening(intent);
}

public boolean recordingIsRunning() {
    return mIsRecording;
}

IsRunning, :)

-1

Source: https://habr.com/ru/post/1683071/


All Articles