Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better implementation #38

Closed
kingdcreations opened this issue Dec 1, 2023 · 4 comments · Fixed by #40
Closed

Better implementation #38

kingdcreations opened this issue Dec 1, 2023 · 4 comments · Fixed by #40
Assignees
Labels
enhancement New feature or request

Comments

@kingdcreations
Copy link
Collaborator

          @riderodd I am facing a problem where the `onFinalResult` event is never triggered, and I believe this change is the reason since everything is cleaned up on the first result. Does it make sense?

Originally posted by @joazvsoares in #32 (comment)

@kingdcreations
Copy link
Collaborator Author

Hi @joazvsoares !

From what I've tried, onFinalResult() event is called when you call stop() on your vosk instance while it's still recognizing.
onFinalResult() will not trigger if you already got a recognition result (onResult() event) as demonstrated in https://github.com/riderodd/react-native-vosk/blob/test/onFinalResult/example/src/App.tsx

I hope it helps you

@kingdcreations
Copy link
Collaborator Author

@riderodd
I cleaned/ linted the code in this PR and added a stop button to test the onFinalResult() event

Maybe we could send a onResult() too instead of a onFinalResult() there:
https://github.com/riderodd/react-native-vosk/blob/test/onFinalResult/android/src/main/java/com/vosk/VoskModule.kt

What do you think ?

@kingdcreations kingdcreations self-assigned this Dec 1, 2023
@joazvsoares
Copy link

joazvsoares commented Dec 2, 2023

Hi @kingdcreations!

Let's imagine the following use case from the vox-browser-demo project:

image

When you click on "Speak" the recognition starts, and you can receive onResult events.

This event is called after silence occured but it doesn't mean we want to stop listening/recognizing.

As you can see here, we can still receive events from the same recognizer instance:

    recognizer.on("result", (message: any) => {
      const result: VoskResult = message.result;
      setUtterances((utt: VoskResult[]) => [...utt, result]);
    });

The issue I see with the current implementation is:

The current onResult function is deliberately closing the recognition instance after the first result, thereby removing the ability to continuously receive more results.

The role of the start function can be confusing, as it is atypical for a "start" function to also return results.

My proposal is to define a start function that purely initiates the process without returning results, introduce a separate function responsible for returning the first result if needed, and also make it up to the client to decide when to close the recognition instance.

@kingdcreations
Copy link
Collaborator Author

Hi @joazvsoares,

Yeah it seems to be a better implementation, I'll work on a pull request for a potential v2

@kingdcreations kingdcreations added the enhancement New feature or request label Dec 4, 2023
@kingdcreations kingdcreations changed the title @riderodd I am facing a problem where the onFinalResult event is never triggered, and I believe this change is the reason since everything is cleaned up on the first result. Does it make sense? Better implementation Dec 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants