JavaScript API with WebAssembly for speaker diarization (#1414)
#1408 uses [node-addon-api](https://github.com/nodejs/node-addon-api) to call C API from JavaScript, whereas this pull request uses WebAssembly to call C API from JavaScript.
This commit is contained in:
@@ -70,6 +70,17 @@ set(exported_functions
|
||||
SherpaOnnxDestroySpeechSegment
|
||||
SherpaOnnxVoiceActivityDetectorReset
|
||||
SherpaOnnxVoiceActivityDetectorFlush
|
||||
# Speaker diarization
|
||||
SherpaOnnxCreateOfflineSpeakerDiarization
|
||||
SherpaOnnxDestroyOfflineSpeakerDiarization
|
||||
SherpaOnnxOfflineSpeakerDiarizationDestroyResult
|
||||
SherpaOnnxOfflineSpeakerDiarizationDestroySegment
|
||||
SherpaOnnxOfflineSpeakerDiarizationGetSampleRate
|
||||
SherpaOnnxOfflineSpeakerDiarizationProcess
|
||||
SherpaOnnxOfflineSpeakerDiarizationProcessWithCallback
|
||||
SherpaOnnxOfflineSpeakerDiarizationResultGetNumSegments
|
||||
SherpaOnnxOfflineSpeakerDiarizationResultSortByStartTime
|
||||
SherpaOnnxOfflineSpeakerDiarizationSetConfig
|
||||
#
|
||||
SherpaOnnxFileExists
|
||||
SherpaOnnxReadWave
|
||||
@@ -109,6 +120,7 @@ install(
|
||||
${CMAKE_SOURCE_DIR}/wasm/tts/sherpa-onnx-tts.js
|
||||
${CMAKE_SOURCE_DIR}/wasm/kws/sherpa-onnx-kws.js
|
||||
${CMAKE_SOURCE_DIR}/wasm/vad/sherpa-onnx-vad.js
|
||||
${CMAKE_SOURCE_DIR}/wasm/speaker-diarization/sherpa-onnx-speaker-diarization.js
|
||||
${CMAKE_SOURCE_DIR}/wasm/nodejs/sherpa-onnx-wave.js
|
||||
"$<TARGET_FILE_DIR:sherpa-onnx-wasm-nodejs>/sherpa-onnx-wasm-nodejs.js"
|
||||
"$<TARGET_FILE_DIR:sherpa-onnx-wasm-nodejs>/sherpa-onnx-wasm-nodejs.wasm"
|
||||
|
||||
@@ -12,7 +12,6 @@ Remember to rename the downloaded files.
|
||||
|
||||
The following is an example.
|
||||
|
||||
|
||||
```bash
|
||||
cd wasm/speaker-diarization/assets/
|
||||
|
||||
@@ -22,9 +21,6 @@ rm sherpa-onnx-pyannote-segmentation-3-0.tar.bz2
|
||||
cp sherpa-onnx-pyannote-segmentation-3-0/model.onnx ./segmentation.onnx
|
||||
rm -rf sherpa-onnx-pyannote-segmentation-3-0
|
||||
|
||||
|
||||
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/speaker-recongition-models/3dspeaker_speech_eres2net_base_sv_zh-cn_3dspeaker_16k.onnx
|
||||
mv 3dspeaker_speech_eres2net_base_sv_zh-cn_3dspeaker_16k.onnx ./embedding.onnx
|
||||
|
||||
|
||||
```
|
||||
|
||||
@@ -64,7 +64,7 @@ function initSherpaOnnxOfflineSpeakerSegmentationModelConfig(config, Module) {
|
||||
Module.setValue(ptr + offset, config.numThreads || 1, 'i32');
|
||||
offset += 4;
|
||||
|
||||
Module.setValue(ptr + offset, config.debug || 1, 'i32');
|
||||
Module.setValue(ptr + offset, config.debug || 0, 'i32');
|
||||
offset += 4;
|
||||
|
||||
const providerLen = Module.lengthBytesUTF8(config.provider || 'cpu') + 1;
|
||||
@@ -103,7 +103,7 @@ function initSherpaOnnxSpeakerEmbeddingExtractorConfig(config, Module) {
|
||||
Module.setValue(ptr + offset, config.numThreads || 1, 'i32');
|
||||
offset += 4;
|
||||
|
||||
Module.setValue(ptr + offset, config.debug || 1, 'i32');
|
||||
Module.setValue(ptr + offset, config.debug || 0, 'i32');
|
||||
offset += 4;
|
||||
|
||||
Module.setValue(ptr + offset, buffer + modelLen, 'i8*');
|
||||
@@ -270,11 +270,15 @@ class OfflineSpeakerDiarization {
|
||||
}
|
||||
|
||||
function createOfflineSpeakerDiarization(Module, myConfig) {
|
||||
const config = {
|
||||
let config = {
|
||||
segmentation: {
|
||||
pyannote: {model: './segmentation.onnx'},
|
||||
debug: 1,
|
||||
},
|
||||
embedding: {
|
||||
model: './embedding.onnx',
|
||||
debug: 1,
|
||||
},
|
||||
embedding: {model: './embedding.onnx'},
|
||||
clustering: {numClusters: -1, threshold: 0.5},
|
||||
minDurationOn: 0.3,
|
||||
minDurationOff: 0.5,
|
||||
|
||||
Reference in New Issue
Block a user