-
Notifications
You must be signed in to change notification settings - Fork 445
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add C API for spoken language identification. (#695)
- Loading branch information
1 parent
0d258dd
commit ab7cff2
Showing
18 changed files
with
363 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
log() { | ||
# This function is from espnet | ||
local fname=${BASH_SOURCE[1]##*/} | ||
echo -e "$(date '+%Y-%m-%d %H:%M:%S') (${fname}:${BASH_LINENO[0]}:${FUNCNAME[1]}) $*" | ||
} | ||
|
||
echo "SLID_EXE is $SLID_EXE" | ||
echo "PATH: $PATH" | ||
|
||
|
||
log "------------------------------------------------------------" | ||
log "Download whisper tiny for spoken language identification " | ||
log "------------------------------------------------------------" | ||
|
||
rm -rf sherpa-onnx-whisper-tiny* | ||
curl -LS -O https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-whisper-tiny.tar.bz2 | ||
tar xvf sherpa-onnx-whisper-tiny.tar.bz2 | ||
rm sherpa-onnx-whisper-tiny.tar.bz2 | ||
|
||
$SLID_EXE | ||
|
||
rm -rf sherpa-onnx-whisper-tiny* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -113,6 +113,7 @@ jobs: | |
git config --global user.email "[email protected]" | ||
git config --global user.name "Fangjun Kuang" | ||
rm -rf huggingface | ||
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/csukuangfj/sherpa-onnx-libs huggingface | ||
cd huggingface | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,6 +90,7 @@ jobs: | |
git config --global user.email "[email protected]" | ||
git config --global user.name "Fangjun Kuang" | ||
rm -rf huggingface | ||
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/csukuangfj/sherpa-onnx-libs huggingface | ||
cd huggingface | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -123,8 +123,15 @@ jobs: | |
name: release-${{ matrix.build_type }}-${{ matrix.shared_lib }} | ||
path: build/bin/* | ||
|
||
- name: Test spoken language identification | ||
if: matrix.build_type != 'Debug' | ||
- name: Test spoken language identification (C API) | ||
shell: bash | ||
run: | | ||
export PATH=$PWD/build/bin:$PATH | ||
export SLID_EXE=spoken-language-identification-c-api | ||
.github/scripts/test-c-api.sh | ||
- name: Test spoken language identification (C++ API) | ||
shell: bash | ||
run: | | ||
export PATH=$PWD/build/bin:$PATH | ||
|
@@ -243,6 +250,7 @@ jobs: | |
git config --global user.email "[email protected]" | ||
git config --global user.name "Fangjun Kuang" | ||
rm -rf huggingface | ||
GIT_LFS_SKIP_SMUDGE=1 git clone https://huggingface.co/csukuangfj/sherpa-onnx-libs huggingface | ||
cd huggingface | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -85,3 +85,4 @@ log | |
vits-piper-* | ||
vits-coqui-* | ||
vits-mms-* | ||
*.tar.bz2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
|
||
// We assume you have pre-downloaded the whisper multi-lingual models | ||
// from https://github.com/k2-fsa/sherpa-onnx/releases/tag/asr-models | ||
// An example command to download the "tiny" whisper model is given below: | ||
// | ||
// clang-format off | ||
// | ||
// wget https://github.com/k2-fsa/sherpa-onnx/releases/download/asr-models/sherpa-onnx-whisper-tiny.tar.bz2 | ||
// tar xvf sherpa-onnx-whisper-tiny.tar.bz2 | ||
// rm sherpa-onnx-whisper-tiny.tar.bz2 | ||
// | ||
// clang-format on | ||
|
||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "sherpa-onnx/c-api/c-api.h" | ||
|
||
int32_t main() { | ||
SherpaOnnxSpokenLanguageIdentificationConfig config; | ||
|
||
memset(&config, 0, sizeof(config)); | ||
|
||
config.whisper.encoder = "./sherpa-onnx-whisper-tiny/tiny-encoder.int8.onnx"; | ||
config.whisper.decoder = "./sherpa-onnx-whisper-tiny/tiny-decoder.int8.onnx"; | ||
config.num_threads = 1; | ||
config.debug = 1; | ||
config.provider = "cpu"; | ||
|
||
const SherpaOnnxSpokenLanguageIdentification *slid = | ||
SherpaOnnxCreateSpokenLanguageIdentification(&config); | ||
if (!slid) { | ||
fprintf(stderr, "Failed to create spoken language identifier"); | ||
return -1; | ||
} | ||
|
||
// You can find more test waves from | ||
// https://hf-mirror.com/spaces/k2-fsa/spoken-language-identification/tree/main/test_wavs | ||
const char *wav_filename = "./sherpa-onnx-whisper-tiny/test_wavs/0.wav"; | ||
const SherpaOnnxWave *wave = SherpaOnnxReadWave(wav_filename); | ||
if (wave == NULL) { | ||
fprintf(stderr, "Failed to read %s\n", wav_filename); | ||
return -1; | ||
} | ||
|
||
SherpaOnnxOfflineStream *stream = | ||
SherpaOnnxSpokenLanguageIdentificationCreateOfflineStream(slid); | ||
|
||
AcceptWaveformOffline(stream, wave->sample_rate, wave->samples, | ||
wave->num_samples); | ||
|
||
const SherpaOnnxSpokenLanguageIdentificationResult *result = | ||
SherpaOnnxSpokenLanguageIdentificationCompute(slid, stream); | ||
|
||
fprintf(stderr, "wav_filename: %s\n", wav_filename); | ||
fprintf(stderr, "Detected language: %s\n", result->lang); | ||
|
||
SherpaOnnxDestroySpokenLanguageIdentificationResult(result); | ||
DestroyOfflineStream(stream); | ||
SherpaOnnxFreeWave(wave); | ||
SherpaOnnxDestroySpokenLanguageIdentification(slid); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.