Git Product home page Git Product logo

Comments (10)

sdkcarlos avatar sdkcarlos commented on June 12, 2024 1

@Danyzzz The speech recognizer doesn't offer such a continuous mode. However i've achieved to make a "continuous mode" in the same way that everybody does (and with acceptable results) with the Speech Recognition API in the browser : once the speech finishes, restart it again.

However i've faced the 2 obvious problems:

  1. The success callback is executed only once (read how to solve it here).
  2. As we need to use the same success callback to send results, we need to filter someway with Javascript when the result is sent from Java to Javascript (to know wheter the plugins says that the speech recognition ends or the results were retrieven). We can simply send an object from Java to JS with the structure:
{
    "event":"event-name",
    // Only for the onResult event
    "matches": ["Recognized text","Recognized text","Recognized text"]
}

Then, the RecognitionListener events of the Java code should be modified too as follows (returns the previously mentioned structure):

@Override
public void onEndOfSpeech() {
    try {
        JSONObject response = new JSONObject();
        response.put("event", "speech.onend");
        callbackContext.success(response.toString());
    } catch (Exception e) {
        e.printStackTrace();
        callbackContext.error(e.getMessage());
    }
}

@Override
public void onResults(Bundle results) {
    ArrayList<String> matches = results.getStringArrayList(SpeechRecognizer.RESULTS_RECOGNITION);
    Log.d(LOG_TAG, "SpeechRecognitionListener results: " + matches);

    try {
        JSONObject response = new JSONObject();
        // Send type of event "on result"
        response.put("event", "speech.onresults");
        // Send recognized text
        response.put("matches", new JSONArray(matches))
        callbackContext.success(response.toString());
    } catch (Exception e) {
        e.printStackTrace();
        callbackContext.error(e.getMessage());
    }
}

And with Javascript (speechRecognition.js) would be now:

startListening: function (successCallback, errorCallback, options) {
    options = options || {};
    cordova.exec(function (data) {
        var response = JSON.parse(data);

        // Note that you need to add some way of conditional to know wheter the continuous mode is used or the simple mode
        if (response.event == "speech.onend") {
            // Note that you need to wait 500ms, otherwise the error "recognition busy" will be triggered.
            setTimeout(function () {
                // Restart the recognition with the callbacks 
                window.plugins.speechRecognition.startListening(successCallback, errorCallback, options);
            }, 500);
        } else if (response.event == "speech.onresults") {
            console.log("Hey something was recognized, check out : ", response.matches);
        }

    }, errorCallback, 'SpeechRecognition', 'startListening', [options.language, options.matches, options.prompt, options.showPartial, options.showPopup]);
},

However i won't make a pull request because that would modify the entire structure in which the plugins works, i just let the idea here in case that someone really needs to make it work in continuous mode. Note that you need figure out how to set a "continuous option" to know when to start the plugin in continuous mode or normal mode.

from cordova-plugin-speechrecognition.

pbakondy avatar pbakondy commented on June 12, 2024

It is possible on iOS

from cordova-plugin-speechrecognition.

Danyzzz avatar Danyzzz commented on June 12, 2024

I'm interested on Android... Like a "ok Google"

from cordova-plugin-speechrecognition.

lsim6580 avatar lsim6580 commented on June 12, 2024

looking at the google docs it looks like they support continuous speech, will this get implemented?

from cordova-plugin-speechrecognition.

renanbrenovital avatar renanbrenovital commented on June 12, 2024

@sdkcarlos Thank you very much, I really needed to leave in continuous mode. I need some help to implement. I have modified the code but it is giving the following error:

..\pbakondy\S
peechRecognition.java:279: error: cannot find symbol
            JSONObject response = new JSONObject();
            ^

from cordova-plugin-speechrecognition.

Danyzzz avatar Danyzzz commented on June 12, 2024

There are news for use continuos mode?

from cordova-plugin-speechrecognition.

ragcsalo avatar ragcsalo commented on June 12, 2024

also how does it work on iOS?

from cordova-plugin-speechrecognition.

hiteshtare avatar hiteshtare commented on June 12, 2024

I need to develop an app where speech recognition will be continous in order to detect hotword for both iOS and Android platforms , Does Speech Recognition Continuos mode is supported in Ionic v5?

from cordova-plugin-speechrecognition.

dineshd1998 avatar dineshd1998 commented on June 12, 2024

@hiteshtare Bro did you get any solution for this bro?

from cordova-plugin-speechrecognition.

JulienLecoq avatar JulienLecoq commented on June 12, 2024

I was also looking to continuous speech recognition, unfortunately it's still not supported and consumes a lot of power to restart speech recognition every time (see: https://developer.apple.com/documentation/speech/sfspeechrecognizer with the part on Create a Great User Experience for Speech Recognition).

I will try the wake word service of Porcupine : https://picovoice.ai/docs/porcupine/. The drawback is that it's a paid service if you have more than 3 users that use the service.

from cordova-plugin-speechrecognition.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.