name: export-kokoro-to-onnx on: push: branches: - refactor-kokoro-2 workflow_dispatch: concurrency: group: export-kokoro-to-onnx-${{ github.ref }} cancel-in-progress: true jobs: export-kokoro-to-onnx: if: github.repository_owner == 'k2-fsa' || github.repository_owner == 'csukuangfj' name: export kokoro ${{ matrix.version }} runs-on: ${{ matrix.os }} strategy: fail-fast: false matrix: os: [ubuntu-latest] version: ["0.19", "1.0", "1.1-zh"] 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 kokoro "numpy<=1.26.4" onnx==1.16.0 onnxruntime==1.17.1 librosa soundfile piper_phonemize -f https://k2-fsa.github.io/icefall/piper_phonemize.html misaki[en] misaki[zh] torch==2.6.0+cpu -f https://download.pytorch.org/whl/torch sherpa-onnx - name: Run env: HF_TOKEN: ${{ secrets.HF_TOKEN }} shell: bash run: | curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/espeak-ng-data.tar.bz2 tar xf espeak-ng-data.tar.bz2 rm espeak-ng-data.tar.bz2 cp -a ./espeak-ng-data ./scripts/kokoro/v0.19 cp -a ./espeak-ng-data ./scripts/kokoro/v1.0 cp -a ./espeak-ng-data ./scripts/kokoro/v1.1-zh git config --global user.email "csukuangfj@gmail.com" git config --global user.name "Fangjun Kuang" cd scripts/kokoro v=${{ matrix.version }} if [[ $v = "0.19" ]]; then cd v0.19 ./run.sh if false; then # generate samples git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-tts-samples hf mkdir -p hf/kokoro/v0.19/mp3 ./generate_samples.py pushd hf git pull git add . git commit -m 'add kokoro samples for v0.19' git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-tts-samples main popd rm -rf hf fi elif [[ $v == "1.0" ]]; then cd v1.0 ./run.sh if false; then git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-tts-samples hf mkdir -p hf/kokoro/v1.0/mp3 curl -SL -O https://github.com/csukuangfj/cppjieba/releases/download/sherpa-onnx-2024-04-19/dict.tar.bz2 tar xvf dict.tar.bz2 rm dict.tar.bz2 curl -SL -o date-zh.fst https://huggingface.co/csukuangfj/icefall-tts-aishell3-vits-low-2024-04-06/resolve/main/data/date.fst curl -SL -o number-zh.fst https://huggingface.co/csukuangfj/icefall-tts-aishell3-vits-low-2024-04-06/resolve/main/data/number.fst curl -SL -o phone-zh.fst https://huggingface.co/csukuangfj/icefall-tts-aishell3-vits-low-2024-04-06/resolve/main/data/phone.fst ./generate_samples.py pushd hf git pull git add . git commit -m 'add kokoro samples for v1.0' git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-tts-samples main popd rm -rf hf fi elif [[ $v == "1.1-zh" ]]; then cd v1.1-zh ./run.sh if false; then git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-tts-samples hf mkdir -p hf/kokoro/v1.1-zh/mp3 curl -SL -O https://github.com/csukuangfj/cppjieba/releases/download/sherpa-onnx-2024-04-19/dict.tar.bz2 tar xvf dict.tar.bz2 rm dict.tar.bz2 curl -SL -o date-zh.fst https://huggingface.co/csukuangfj/icefall-tts-aishell3-vits-low-2024-04-06/resolve/main/data/date.fst curl -SL -o number-zh.fst https://huggingface.co/csukuangfj/icefall-tts-aishell3-vits-low-2024-04-06/resolve/main/data/number.fst curl -SL -o phone-zh.fst https://huggingface.co/csukuangfj/icefall-tts-aishell3-vits-low-2024-04-06/resolve/main/data/phone.fst ./generate_samples.py pushd hf git pull git add . git commit -m 'add kokoro samples for v1.1-zh' git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-tts-samples main popd rm -rf hf fi else echo "Unknown version $v" exit 1 fi - name: Collect results 0.19 if: matrix.version == '0.19' shell: bash run: | src=scripts/kokoro/v0.19 d=kokoro-en-v0_19 mkdir $d cp -a LICENSE $d/LICENSE cp -a espeak-ng-data $d/ cp -v $src/model.onnx $d/model.onnx cp -v $src/voices.bin $d/ cp -v $src/tokens.txt $d/ cp -v $src/../README.md $d/README.md ls -lh $d/ tar cjfv $d.tar.bz2 $d ls -lh $d.tar.bz2 - name: Collect results 0.19 (int8) if: matrix.version == '0.19' shell: bash run: | src=scripts/kokoro/v0.19 d=kokoro-int8-en-v0_19 mkdir $d cp -a LICENSE $d/LICENSE cp -a espeak-ng-data $d/ cp -v $src/model.int8.onnx $d/model.int8.onnx cp -v $src/voices.bin $d/ cp -v $src/tokens.txt $d/ cp -v $src/../README.md $d/README.md ls -lh $d/ tar cjfv $d.tar.bz2 $d ls -lh $d.tar.bz2 - name: Collect results 1.0 if: matrix.version == '1.0' shell: bash run: | curl -SL -O https://github.com/csukuangfj/cppjieba/releases/download/sherpa-onnx-2024-04-19/dict.tar.bz2 tar xvf dict.tar.bz2 rm dict.tar.bz2 curl -SL -o date-zh.fst https://huggingface.co/csukuangfj/icefall-tts-aishell3-vits-low-2024-04-06/resolve/main/data/date.fst curl -SL -o number-zh.fst https://huggingface.co/csukuangfj/icefall-tts-aishell3-vits-low-2024-04-06/resolve/main/data/number.fst curl -SL -o phone-zh.fst https://huggingface.co/csukuangfj/icefall-tts-aishell3-vits-low-2024-04-06/resolve/main/data/phone.fst src=scripts/kokoro/v1.0 d=kokoro-multi-lang-v1_0 mkdir $d cp -v LICENSE $d/LICENSE cp -a espeak-ng-data $d/ cp -v $src/kokoro.onnx $d/model.onnx cp -v $src/voices.bin $d/ cp -v $src/tokens.txt $d/ cp -v $src/lexicon*.txt $d/ cp -v $src/README.md $d/README.md cp -av dict $d/ cp -v ./*.fst $d/ ls -lh $d/ echo "---" ls -lh $d/dict tar cjfv $d.tar.bz2 $d rm -rf $d ls -lh $d.tar.bz2 d=kokoro-int8-multi-lang-v1_0 mkdir $d cp -v LICENSE $d/LICENSE cp -a espeak-ng-data $d/ cp -v $src/kokoro.int8.onnx $d/model.int8.onnx cp -v $src/voices.bin $d/ cp -v $src/tokens.txt $d/ cp -v $src/lexicon*.txt $d/ cp -v $src/README.md $d/README.md cp -av dict $d/ cp -v ./*.fst $d/ ls -lh $d/ echo "---" ls -lh $d/dict tar cjfv $d.tar.bz2 $d rm -rf $d ls -lh $d.tar.bz2 - name: Collect results 1.1-zh if: matrix.version == '1.1-zh' shell: bash run: | curl -SL -O https://github.com/csukuangfj/cppjieba/releases/download/sherpa-onnx-2024-04-19/dict.tar.bz2 tar xvf dict.tar.bz2 rm dict.tar.bz2 curl -SL -o date-zh.fst https://huggingface.co/csukuangfj/icefall-tts-aishell3-vits-low-2024-04-06/resolve/main/data/date.fst curl -SL -o number-zh.fst https://huggingface.co/csukuangfj/icefall-tts-aishell3-vits-low-2024-04-06/resolve/main/data/number.fst curl -SL -o phone-zh.fst https://huggingface.co/csukuangfj/icefall-tts-aishell3-vits-low-2024-04-06/resolve/main/data/phone.fst src=scripts/kokoro/v1.1-zh d=kokoro-multi-lang-v1_1 mkdir $d cp -v LICENSE $d/LICENSE cp -a espeak-ng-data $d/ cp -v $src/kokoro.onnx $d/model.onnx cp -v $src/voices.bin $d/ cp -v $src/tokens.txt $d/ cp -v $src/lexicon*.txt $d/ cp -v $src/README.md $d/README.md cp -av dict $d/ cp -v ./*.fst $d/ ls -lh $d/ echo "---" ls -lh $d/dict tar cjfv $d.tar.bz2 $d rm -rf $d ls -lh $d.tar.bz2 d=kokoro-int8-multi-lang-v1_1 mkdir $d cp -v LICENSE $d/LICENSE cp -a espeak-ng-data $d/ cp -v $src/kokoro.int8.onnx $d/model.int8.onnx cp -v $src/voices.bin $d/ cp -v $src/tokens.txt $d/ cp -v $src/lexicon*.txt $d/ cp -v $src/README.md $d/README.md cp -av dict $d/ cp -v ./*.fst $d/ ls -lh $d/ echo "---" ls -lh $d/dict tar cjfv $d.tar.bz2 $d rm -rf $d ls -lh $d.tar.bz2 echo "---" ls -lh *.tar.bz2 - 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: tts-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: tts-models - name: Publish to huggingface 0.19 if: matrix.version == '0.19' 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" dirs=( kokoro-en-v0_19 # kokoro-int8-en-v0_19 ) export GIT_LFS_SKIP_SMUDGE=1 export GIT_CLONE_PROTECTION_ACTIVE=false for d in ${dirs[@]}; do rm -rf huggingface git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/kokoro-en-v0_19 huggingface cd huggingface rm -rf ./* git lfs track "*.onnx" git lfs track af_dict git lfs track ar_dict git lfs track cmn_dict git lfs track da_dict en_dict fa_dict hu_dict ia_dict it_dict lb_dict phondata ru_dict ta_dict git lfs track ur_dict yue_dict cp -a ../$d ./ git add . ls -lh git status git commit -m "add models" git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/kokoro-en-v0_19 main || true done - name: Publish to huggingface 1.0 float32 if: matrix.version == '1.0' 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 git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/kokoro-multi-lang-v1_0 huggingface cd huggingface rm -rf ./* git fetch git pull git lfs track "cmn_dict" git lfs track "ru_dict" git lfs track "*.wav" git lfs track "lexicon*.txt" cp -a ../espeak-ng-data ./ cp -v ../scripts/kokoro/v1.0/kokoro.onnx ./model.onnx cp -v ../scripts/kokoro/v1.0/tokens.txt . cp -v ../scripts/kokoro/v1.0/voices.bin . cp -v ../scripts/kokoro/v1.0/lexicon*.txt . cp -v ../scripts/kokoro/v1.0/README.md ./README.md cp -v ../LICENSE ./ cp -av ../dict ./ cp -v ../*.fst ./ git lfs track "*.onnx" git add . ls -lh git status git commit -m "add models" git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/kokoro-multi-lang-v1_0 main || true - name: Publish to huggingface 1.0 int8 if: matrix.version == '1.0' 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 git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/kokoro-int8-multi-lang-v1_0 huggingface cd huggingface rm -rf ./* git fetch git pull git lfs track "cmn_dict" git lfs track "ru_dict" git lfs track "af_dict" git lfs track "ar_dict" git lfs track "da_dict" git lfs track "en_dict" git lfs track "fa_dict" git lfs track "hu_dict" git lfs track "ia_dict" git lfs track "it_dict" git lfs track "lb_dict" git lfs track "phondata" git lfs track "ta_dict" git lfs track "ur_dict" git lfs track "yue_dict" git lfs track "*.wav" git lfs track "lexicon*.txt" cp -a ../espeak-ng-data ./ cp -v ../scripts/kokoro/v1.0/kokoro.int8.onnx ./model.int8.onnx cp -v ../scripts/kokoro/v1.0/tokens.txt . cp -v ../scripts/kokoro/v1.0/voices.bin . cp -v ../scripts/kokoro/v1.0/lexicon*.txt . cp -v ../scripts/kokoro/v1.0/README.md ./README.md cp -v ../LICENSE ./ cp -av ../dict ./ cp -v ../*.fst ./ git lfs track "*.onnx" git add . ls -lh git status git commit -m "add models" git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/kokoro-int8-multi-lang-v1_0 main || true - name: Publish to huggingface 1.1-zh if: matrix.version == '1.1-zh' 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 git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/kokoro-multi-lang-v1_1 huggingface cd huggingface rm -rf ./* git fetch git pull git lfs track "cmn_dict" git lfs track "ru_dict" git lfs track "*.wav" git lfs track "lexicon*.txt" cp -a ../espeak-ng-data ./ cp -v ../scripts/kokoro/v1.1-zh/kokoro.onnx ./model.onnx cp -v ../scripts/kokoro/v1.1-zh/tokens.txt . cp -v ../scripts/kokoro/v1.1-zh/voices.bin . cp -v ../scripts/kokoro/v1.1-zh/lexicon*.txt . cp -v ../scripts/kokoro/v1.1-zh/README.md ./README.md cp -v ../LICENSE ./ cp -av ../dict ./ cp -v ../*.fst ./ git lfs track "*.onnx" git add . ls -lh git status git commit -m "add models" git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/kokoro-multi-lang-v1_1 main || true - name: Publish to huggingface 1.1-zh-int8 if: matrix.version == '1.1-zh' 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 git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/kokoro-int8-multi-lang-v1_1 huggingface cd huggingface rm -rf ./* git fetch git pull git lfs track "cmn_dict" git lfs track "ru_dict" git lfs track "*.wav" git lfs track "lexicon*.txt" cp -a ../espeak-ng-data ./ cp -v ../scripts/kokoro/v1.1-zh/kokoro.int8.onnx ./model.int8.onnx cp -v ../scripts/kokoro/v1.1-zh/tokens.txt . cp -v ../scripts/kokoro/v1.1-zh/voices.bin . cp -v ../scripts/kokoro/v1.1-zh/lexicon*.txt . cp -v ../scripts/kokoro/v1.1-zh/README.md ./README.md cp -v ../LICENSE ./ cp -av ../dict ./ cp -v ../*.fst ./ git lfs track "*.onnx" git add . ls -lh git status git commit -m "add models" git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/kokoro-int8-multi-lang-v1_1 main || true