From d5da9430e89a6ac05ead12ef01e7d501e5192904 Mon Sep 17 00:00:00 2001 From: Fangjun Kuang Date: Mon, 10 Feb 2025 18:23:40 +0800 Subject: [PATCH] Add PengChengStarling models to sherpa-onnx (#1835) --- .../workflows/export-peng-cheng-starling.yaml | 123 ++++++++++++++++++ scripts/matcha-tts/README.md | 2 +- scripts/peng-cheng-starling/.gitignore | 3 + scripts/peng-cheng-starling/README.md | 4 + .../peng-cheng-starling/quantize_models.py | 22 ++++ scripts/peng-cheng-starling/run.sh | 36 +++++ sherpa-onnx/csrc/offline-tts.h | 2 +- 7 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/export-peng-cheng-starling.yaml create mode 100644 scripts/peng-cheng-starling/.gitignore create mode 100644 scripts/peng-cheng-starling/README.md create mode 100755 scripts/peng-cheng-starling/quantize_models.py create mode 100755 scripts/peng-cheng-starling/run.sh diff --git a/.github/workflows/export-peng-cheng-starling.yaml b/.github/workflows/export-peng-cheng-starling.yaml new file mode 100644 index 000000000..c43de9f74 --- /dev/null +++ b/.github/workflows/export-peng-cheng-starling.yaml @@ -0,0 +1,123 @@ +name: export-peng-cheng-starling-to-onnx + +on: + push: + branches: + - export-peng-cheng-starling-2 + + workflow_dispatch: + +concurrency: + group: export-peng-cheng-starling-to-onnx-${{ github.ref }} + cancel-in-progress: true + +jobs: + export-peng-cheng-starling-to-onnx: + if: github.repository_owner == 'k2-fsa' || github.repository_owner == 'csukuangfj' + name: export peng cheng starling ${{ matrix.version }} + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + os: [ubuntu-latest] + python-version: ["3.10"] + + steps: + - uses: actions/checkout@v4 + + - name: Setup Python ${{ matrix.python-version }} + uses: actions/setup-python@v5 + with: + python-version: ${{ matrix.python-version }} + + - name: Install Python dependencies + shell: bash + run: | + pip install "numpy<=1.26.4" onnx==1.16.0 onnxruntime==1.17.1 + + - name: Run + shell: bash + run: | + cd scripts/peng-cheng-starling + ./run.sh + python3 ./quantize_models.py + + ls -lh + rm encoder-epoch-75-avg-11-chunk-16-left-128.onnx + rm joiner-epoch-75-avg-11-chunk-16-left-128.onnx + echo "----" + ls -lh + + + - name: Collect results ${{ matrix.version }} + shell: bash + run: | + src=scripts/peng-cheng-starling + d=sherpa-onnx-streaming-zipformer-ar_en_id_ja_ru_th_vi_zh-2025-02-10 + mkdir $d + + mv -v $src/*.onnx $d + cp -v $src/README.md $d + cp -v $src/bpe.model $d + cp -av $src/test_wavs $d + + ls -lh $d/ + tar cjfv $d.tar.bz2 $d + + ls -lh $d.tar.bz2 + + - name: Publish to huggingface ${{ matrix.version }} + env: + HF_TOKEN: ${{ secrets.HF_TOKEN }} + uses: nick-fields/retry@v3 + with: + max_attempts: 20 + timeout_seconds: 200 + shell: bash + command: | + git config --global user.email "csukuangfj@gmail.com" + git config --global user.name "Fangjun Kuang" + + rm -rf huggingface + export GIT_LFS_SKIP_SMUDGE=1 + export GIT_CLONE_PROTECTION_ACTIVE=false + + src=sherpa-onnx-streaming-zipformer-ar_en_id_ja_ru_th_vi_zh-2025-02-10 + + git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/$src huggingface + cd huggingface + rm -rf ./* + git fetch + git pull + + cp -av ../$src/* ./ + + git lfs track "*.onnx" + git add . + + ls -lh + + git status + + git commit -m "add models" + git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/$src main || true + + - name: Release + if: github.repository_owner == 'csukuangfj' + uses: svenstaro/upload-release-action@v2 + with: + file_glob: true + file: ./*.tar.bz2 + overwrite: true + repo_name: k2-fsa/sherpa-onnx + repo_token: ${{ secrets.UPLOAD_GH_SHERPA_ONNX_TOKEN }} + tag: asr-models + + - name: Release + if: github.repository_owner == 'k2-fsa' + uses: svenstaro/upload-release-action@v2 + with: + file_glob: true + file: ./*.tar.bz2 + overwrite: true + tag: asr-models diff --git a/scripts/matcha-tts/README.md b/scripts/matcha-tts/README.md index f04826e66..b3bc2e658 100644 --- a/scripts/matcha-tts/README.md +++ b/scripts/matcha-tts/README.md @@ -1,6 +1,6 @@ # Introduction -This folder contains script for adding meta data to tts models +This folder contains scripts for adding meta data to tts models from https://github.com/shivammehta25/Matcha-TTS Note: If you use icefall to train a MatchaTTS model, you don't need this folder. diff --git a/scripts/peng-cheng-starling/.gitignore b/scripts/peng-cheng-starling/.gitignore new file mode 100644 index 000000000..1494442bc --- /dev/null +++ b/scripts/peng-cheng-starling/.gitignore @@ -0,0 +1,3 @@ +bpe.model +*.wav +*.onnx diff --git a/scripts/peng-cheng-starling/README.md b/scripts/peng-cheng-starling/README.md new file mode 100644 index 000000000..4a8056d1b --- /dev/null +++ b/scripts/peng-cheng-starling/README.md @@ -0,0 +1,4 @@ +# Introduction + +This folder contains scripts for files from +https://github.com/yangb05/PengChengStarling diff --git a/scripts/peng-cheng-starling/quantize_models.py b/scripts/peng-cheng-starling/quantize_models.py new file mode 100755 index 000000000..9c7933c68 --- /dev/null +++ b/scripts/peng-cheng-starling/quantize_models.py @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 +from onnxruntime.quantization import QuantType, quantize_dynamic +from pathlib import Path + + +def main(): + suffix = "epoch-75-avg-11-chunk-16-left-128" + + for m in ["encoder", "joiner"]: + if Path(f"{m}-{suffix}.int8.onnx").is_file(): + continue + + quantize_dynamic( + model_input=f"./{m}-{suffix}.onnx", + model_output=f"./{m}-{suffix}.int8.onnx", + op_types_to_quantize=["MatMul"], + weight_type=QuantType.QInt8, + ) + + +if __name__ == "__main__": + main() diff --git a/scripts/peng-cheng-starling/run.sh b/scripts/peng-cheng-starling/run.sh new file mode 100755 index 000000000..e32936d23 --- /dev/null +++ b/scripts/peng-cheng-starling/run.sh @@ -0,0 +1,36 @@ +#!/usr/bin/env bash + +set -ex + +if [ ! -f bpe.model ]; then + curl -SL -O https://huggingface.co/stdo/PengChengStarling/resolve/main/bpe.model +fi + +if [ ! -f tokens.txt ]; then + curl -SL -O https://huggingface.co/stdo/PengChengStarling/resolve/main/tokens.txt +fi + +if [ ! -f decoder-epoch-75-avg-11-chunk-16-left-128.onnx ]; then + curl -SL -O https://huggingface.co/stdo/PengChengStarling/resolve/main/decoder-epoch-75-avg-11-chunk-16-left-128.onnx +fi + +if [ ! -f encoder-epoch-75-avg-11-chunk-16-left-128.onnx ]; then + curl -SL -O https://huggingface.co/stdo/PengChengStarling/resolve/main/encoder-epoch-75-avg-11-chunk-16-left-128.onnx +fi + +if [ ! -f joiner-epoch-75-avg-11-chunk-16-left-128.onnx ]; then + curl -SL -O https://huggingface.co/stdo/PengChengStarling/resolve/main/joiner-epoch-75-avg-11-chunk-16-left-128.onnx +fi + +mkdir -p test_wavs +if [ ! -f test_wavs/zh.wav ]; then + curl -SL --output test_wavs/zh.wav https://huggingface.co/marcoyang/sherpa-ncnn-streaming-zipformer-zh-14M-2023-02-23/resolve/main/test_wavs/0.wav +fi + +if [ ! -f test_wavs/en.wav ]; then + curl -SL --output test_wavs/en.wav https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-en-2023-02-21/resolve/main/test_wavs/0.wav +fi + +if [ ! -f test_wavs/ja.wav ]; then + curl -SL --output test_wavs/ja.wav https://huggingface.co/csukuangfj/reazonspeech-k2-v2/resolve/main/test_wavs/5.wav +fi diff --git a/sherpa-onnx/csrc/offline-tts.h b/sherpa-onnx/csrc/offline-tts.h index d1b0b21d0..a505bd38c 100644 --- a/sherpa-onnx/csrc/offline-tts.h +++ b/sherpa-onnx/csrc/offline-tts.h @@ -32,7 +32,7 @@ struct OfflineTtsConfig { // If you set it to -1, then we process all sentences in a single batch. int32_t max_num_sentences = 1; - // A silence interval containing audio samples with value close to 0. + // A silence interval contains audio samples with value close to 0. // // the duration of the new interval is old_duration * silence_scale. float silence_scale = 0.2;