cordova-plugin-speechrecognition icon indicating copy to clipboard operation
cordova-plugin-speechrecognition copied to clipboard

How to identify who has stopped recording?

Open DeeSouza opened this issue 7 years ago • 5 comments

I'm using Ionic 3 and plugin native Speech Recognition: Plugin Ionic Native

My device is an Android 7.0.

So, how to identify who has stopped recording?

The function stopListening is only iOS. But, and in Android?

Thanks in advanced.

DeeSouza avatar Apr 20 '18 21:04 DeeSouza

Hi @DeeSouza, on Android the speech recognition (google assistant technology) auto-stop the recording when the user stop talking while on IOS (siri technology) you have to manually stop the recording through the stopListening method.

Maybe the answer of your question is you have to switch your code execution calling platform.is('ios') and platform.is('android') and use stopListening only on IOS.

texano00 avatar Apr 21 '18 09:04 texano00

Hi @texano00,

Thank you for answer.

But, how would I do when use the parameter showPartial ?

Don't have my code now, but is like this:

isRecording = false;

function startListen()
{
      isRecording = true;

      optionsAndroid = {
         showPartial: true,
         showPopup: false
      };
     this.speech.startListening(optionsAndroid).subscribe(
      matches => {
           isRecording = false;
           this.speechResult = matches[0];
           this.cd.detectChanges();
      }
   );
}

DeeSouza avatar Apr 21 '18 12:04 DeeSouza

I don't know what your application do, but from the doc

If you set showPartial to true on iOS the success callback will be called multiple times until stopListening() called.

I suppose that showPartial has the same effect on Android but i'm not sure.

texano00 avatar Apr 21 '18 16:04 texano00

In monday I post my code and explain better.

Thanks!

DeeSouza avatar Apr 21 '18 16:04 DeeSouza

My code:

// Listen to user
listenForSpeech() {
    this.androidOptions = {
        language: 'pt-BR',
        matches: 1,
        showPopup: false,
        **showPartial: true** // ---------------------------------- SHOW PARTIAL
    };

    this.iosOptions = {
        matches: 1,
        language: 'pt-BR',
        **showPartial: true** // ---------------------------------- SHOW PARTIAL
    };

    if(this.platform.is('android')){
        return this.speech.startListening(this.androidOptions);
    }
    else if(this.platform.is('ios')){
        return this.speech.startListening(this.iosOptions);
    }
}
// Listen to user
async manualSpeech(event){
    this.isRecording = true;

    this.speech.listenForSpeech().subscribe(
        async matches 	=> this.searchManual(matches),
        error 			=> {
            console.log(error);
            this.isRecording = false;
        }
    );
}

// Search query
async searchManual(matches){
    this.speechResult = matches[0];

    if(matches && matches.length > 0){
        this.zone.run(() => {
            this.isRecording 	= false;
            console.log('Send Message'); // --------------------- HERE -------------------------
        });
    }
}

I'm using the parameter showPartial . If I to told "The books is on the table", the console.log('Send Message'); will appear 6 times.

But, I want what this happens only when to stop speech, in ANDROID, so so, only one time.

DeeSouza avatar Apr 23 '18 19:04 DeeSouza