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

How to use InitModel(model) if we DOWNLOAD VOSK MODELS FROM INSIDE APP CODE? #190

Open
botbahlul opened this issue Oct 3, 2022 · 5 comments

Comments

@botbahlul
Copy link

botbahlul commented Oct 3, 2022

I'm trying to add another language model by DOWNLOADING MODELS FROM INSIDE APP CODE

How to use initModel(String model) after downloaded it to local storage?
From my MainActivity.java I downloaded a model from VOSK Models website then extracted that model.zip into /storage/emulated/0/Android/data/MyAppName/files/model).
So, what's next should I do?
Do I need to create UUID?
How to create its UUID from app code (NOT FROM gradle)?

Can you please give some java codes example how to do that?

@botbahlul botbahlul changed the title How to use InitModel(model) if we download models FROM INSDE APP CODE? How to use InitModel(model) if we download models FROM INSIDE APP CODE? Oct 3, 2022
@botbahlul botbahlul changed the title How to use InitModel(model) if we download models FROM INSIDE APP CODE? How to use InitModel(model) if we DOWNLOAD models FROM INSIDE APP CODE? Oct 3, 2022
@botbahlul botbahlul changed the title How to use InitModel(model) if we DOWNLOAD models FROM INSIDE APP CODE? How to use InitModel(model) if we DOWNLOAD VOSK MODELS FROM INSIDE APP CODE? Oct 3, 2022
@reikiJS
Copy link

reikiJS commented Oct 4, 2022

https://note.com/srvhat09/n/n0010ab66ee41
This is my Blog in Japanese, but I hope it is useful.

@nshmyrev
Copy link
Collaborator

nshmyrev commented Oct 4, 2022

In general you don't need UUID. You can check https://github.com/alphacep/vosk-android-service/tree/master/app/src/main/java/org/vosk/service/download, it simply downloads models from our server

@botbahlul
Copy link
Author

botbahlul commented Oct 4, 2022

In general you don't need UUID. You can check https://github.com/alphacep/vosk-android-service/tree/master/app/src/main/java/org/vosk/service/download, it simply downloads models from our server

I'm confused about StorageService.unpack(context, SourcePath, targetPath, completeCallback, errorCallback) function

private void initModel() {
    StorageService.unpack(this, "model-en-us", "model",
            (model) -> {
                this.model = model;
                setUiState(STATE_READY);
            },
            (exception) -> setErrorState("Failed to unpack the model" + exception.getMessage()));
}

from this demo as far as I understand that sourcePath "model-en-us" is refferring to FOLDER NAME IN ASSET IN PC HARDDISK (C:\Users\Toshiba\AndroidStudioProjects\vosk-android-demo\model\src\main\assets\model-en-us)

My question is HOW TO USE THIS StorageService.unpack(this, "model-en-us", "model", completeCallback, errorCallback)

if I downloaded a French-model.zip from MainActivity USING SOME CODES (NOT MANUALLY DOWNLOAD IT THEN PUT IT IN ASSETS FOLDER) then extract it into /storage/emulated/0/Android/data/MyAppName/files/extracted/model-fr-FR

I've tried using this

string_model = "/storage/emulated/0/Android/data/MyAppName/files/extracted/model-fr-FR
";
initModel(string_model);

private void initModel(String string_model) {
    StorageService.unpack(this, string_model, "model",
            (model) -> {
                this.model = model;
                setUiState(STATE_READY);
                recognizeMicrophone();
            },
            (exception) -> setErrorState("Failed to unpack the model" + exception.getMessage()));
}

BUT IT GAVE ME ERRORS

Here's my source code

VoskPoweredLiveSubtitle.zip

but I've deleted the content of "en-US" folder because it's to big to upload here.
That "en-us" folder in my source is just a renamed of "model-en-us" from this demo app vosk-android-demo/models/src/main/assets/model-en-us

so, in case you want to try it you have to copy the content of "model-en-us" from this vosk demo to "en-US" of my source code.

I'm using that initModel(String string_model) function in VoskVoiceRecognizer.java class.

DO YOU MEAN THAT I DON'T NEED TO USE THAT initModel(model) FUNCTION?

JUST DOWNLOAD AND UNZIP TO /Android/data/MyAppName/files/model/fr-FR ?

I've tried that, check my zipped attachment

It gave me error

2022-10-05 02:16:06.475 15304-15304/org.vosk.livesubtitle A/libc: Fatal signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 0x5a4 in tid 15304 (sk.livesubtitle), pid 15304 (sk.livesubtitle)

@botbahlul
Copy link
Author

botbahlul commented Oct 4, 2022

https://note.com/srvhat09/n/n0010ab66ee41 This is my Blog in Japanese, but I hope it is useful.

this is just a MANUAL DOWNLOAD NOT DOWNLOAD BY USING CODES FROM INSIDE MainActivity.java

My problem is

HOW TO USE that StorageService.unpack(Context context, String sourcePath, final String targetPath, final Callback completeCallback, final Callback errorCallback) function in initModel(model)

that sourcePath, how to use it?

@botbahlul
Copy link
Author

botbahlul commented Oct 5, 2022

In general you don't need UUID. You can check https://github.com/alphacep/vosk-android-service/tree/master/app/src/main/java/org/vosk/service/download, it simply downloads models from our server

oh man..
you gave me a bunch of "HAYSTACKS" when the "NEDDLE" I need just a one single line

Model model = new Model("/storage/emulated/0/Android/data/MyAppName/files/extracted_downloded_models/model-fr-FR")

but thanks anyway to TRIGGER me to find it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants