On-device speaker identification (本地说话人识别)
This page describes how to build SherpaOnnxSpeakerIdentification for on-device speaker identification that runs on HarmonyOS.
Open the project with DevEco Studio
You need to first download the code:
# Assume we place it inside /Users/fangjun/open-source
# You can place it anywhere you like.
cd /Users/fangjun/open-source/
git clone https://github.com/k2-fsa/sherpa-onnx
Then start DevEco Studio and follow the screenshots below:
Select a model
The code supports many models for extracting speaker embeddings and you have to select one.
You can find all supported models at
We use the following model
as an example in this document.
Use 3dspeaker_speech_eres2net_base_200k_sv_zh-cn_16k-common.onnx
First, we download it to the rawfile directory.
Caution: You MUST place the file inside the rawfile directory. Otherwise, you would be SAD
later.
cd /Users/fangjun/open-source/sherpa-onnx/harmony-os/SherpaOnnxSpeakerIdentification/entry/src/main/resources/rawfile
wget https://github.com/k2-fsa/sherpa-onnx/releases/download/speaker-recongition-models/3dspeaker_speech_eres2net_base_200k_sv_zh-cn_16k-common.onnx
Please check that your directory looks exactly
like the following:
(py38) fangjuns-MacBook-Pro:rawfile fangjun$ pwd
/Users/fangjun/open-source/sherpa-onnx/harmony-os/SherpaOnnxSpeakerIdentification/entry/src/main/resources/rawfile
(py38) fangjuns-MacBook-Pro:rawfile fangjun$ ls -lh
total 77888
-rw-r--r-- 1 fangjun staff 38M Oct 14 11:41 3dspeaker_speech_eres2net_base_200k_sv_zh-cn_16k-common.onnx
Now we need to change the code to use our selected model.
We have to change SpeakerIdentificationWorker.ets. Please see the following screenshot.
Finally, we can build the project. See the screenshot below:
If you have an emulator, you can now start it.
After the emulator is started, follow the screenshot below to run the app on the emulator:
You should see something like below:
Congratulations!
You have successfully run a on-device speaker identification APP on HarmonyOS!