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

Flutter Android speech identification #1761

Open
erlanherlangga1 opened this issue Jan 24, 2025 · 12 comments
Open

Flutter Android speech identification #1761

erlanherlangga1 opened this issue Jan 24, 2025 · 12 comments

Comments

@erlanherlangga1
Copy link

I wanna build the application for speaker identification using sherpa-onnx on flutter but when extract the embedding audio, it given the empty list. I already debug to check that the file is on assets or not and the code can read the file on the assset.

Image

@csukuangfj
Copy link
Collaborator

csukuangfj commented Jan 24, 2025

Please check.that the extactor is created successfully. You can test if its member ptr is null or not.

Make sure you have initialized sherpa onnx dart binding.

@erlanherlangga1
Copy link
Author

sherpa onnx already initialized with this code:

Image

Image

I see this after read the wav file using readWave, it return 0 sampleRate and i think it failed to read the wav file
Image

@csukuangfj
Copy link
Collaborator

csukuangfj commented Jan 24, 2025

Can you tell us why there is libsherpa-onnx-jni.so in your log?

@csukuangfj
Copy link
Collaborator

I suggest that you first run our dart-api-examples.

We have created the dart package for you.

The init code you posted does not look correct to me.

@erlanherlangga1
Copy link
Author

I see the init code as shown below and there is no android platform, is the speaker identification cannot be used in the flutter application for android?

Image

@csukuangfj
Copy link
Collaborator

This is for pure dart api.

Of course it can be used in Android.

Please see our flutter-examples folder.

@erlanherlangga1
Copy link
Author

I saw flutter-examples folder and there is no speaker identification example.

I use init code above and give this result

Image

@csukuangfj
Copy link
Collaborator

I use init code above and give this result

I hope you can understand that your init code is not correct.


I saw flutter-examples folder and there is no speaker identification example.

I also hope that you know flutter app uses dart programming language and we have provided all dart API you needed to develop a flutter android/ios/windows/linux/macos APP

To given you two examples:

1. Streaming ASR example

https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/streaming-asr/bin

The above code shows how to use dart API for streaming speech recognition.

To use the above dart API in developing a flutter app, we have provided a demo for you at
https://github.com/k2-fsa/sherpa-onnx/tree/master/flutter-examples/streaming_asr

I hope you can spend time learning the above two examples. If you exclude the code for copying assets, for UI, and for microphone in the flutter APP, you can find that every dart API used in the flutter app related to ASR is from the above pure dart example.

2. https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/tts

The above code shows how to use dart API for tts.

To use the above dart API in developing a flutter app, we have provided a demo for you at
https://github.com/k2-fsa/sherpa-onnx/tree/master/flutter-examples/tts

I hope you can spend time learning the above two examples again. If you exclude the code for copying assets, for UI, and for playing audio samples in the flutter APP, you can find that every dart API used in the flutter app related to TTS is from the above pure dart example.

3. https://github.com/k2-fsa/sherpa-onnx/tree/master/dart-api-examples/speaker-identification

The above code shows how to use dart API for speaker identification.

It contains all speaker identification related dart API for developing a flutter android/linux/macos/windows/ios app.

Similarly, you can develop a flutter example by following
https://github.com/k2-fsa/sherpa-onnx/tree/master/flutter-examples/streaming_asr
and
https://github.com/k2-fsa/sherpa-onnx/tree/master/flutter-examples/tts


Hint: To initialize sherpa-onnx in a flutter APP, please refer to

if (!_isInitialized) {
sherpa_onnx.initBindings();

sherpa_onnx.initBindings();

We have done everything for you to use sherpa-onnx in dart. Please don't reinvent the wheel, i.e., don't write your own init code.

Another hint:

sherpa_onnx: ^1.10.41

shows how to introduce the dependency on sherpa-onnx in your flutter app.

You never need to care about which shared lib to use.

@erlanherlangga1
Copy link
Author

thank you for the information,

i wanna ask again, how to read model directly from the asset, i write the code like this

Image

but show the error

Image

@csukuangfj
Copy link
Collaborator

For Flutter app, you need to first copy the asset.files to some path. You can find the asset file.copying code in our flutter tts or asr code.

Note that the copy is required due to the.sandbox mechanism in flutter.

You cannot pass the asset file path to our dart api.

@erlanherlangga1
Copy link
Author

Thank you, i solved the problem.

Then, how can we know matching score for speaker identification in dart??

@csukuangfj
Copy link
Collaborator

please.see.our.dart api.examples.

We.have provided all APIs you need.

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

No branches or pull requests

2 participants