Upload matcha tts zh-en model (#2865)

This commit is contained in:
Fangjun Kuang authored and GitHub committed 2025-12-05 11:45:41 +08:00
1 parent ab479d8e01
commit e6a6599f59
4 files changed
+211 -6

No files matched your search

+163
View File
@@ -0,0 +1,163 @@
name: export-matcha-zh-en-to-onnx
on:
push:
branches:
- matcha-zh-en
workflow_dispatch:
concurrency:
group: export-matcha-zh-en-to-onnx-${{ github.ref }}
cancel-in-progress: true
jobs:
export-matcha-zh-en-to-onnx:
if: github.repository_owner == 'k2-fsa' || github.repository_owner == 'csukuangfj'
name: export matcha zh-en ${{ 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" pypinyin soundfile \
sherpa-onnx -f https://k2-fsa.github.io/sherpa/onnx/cpu.html
- name: Generate samples
env:
HF_TOKEN: ${{ secrets.HF_TOKEN }}
shell: bash
run: |
cd scripts/matcha-tts/zh-en
git config --global user.email "csukuangfj@gmail.com"
git config --global user.name "Fangjun Kuang"
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/matcha-icefall-zh-en.tar.bz2
tar xvf matcha-icefall-zh-en.tar.bz2
rm matcha-icefall-zh-en.tar.bz2
curl -SL -O https://github.com/k2-fsa/sherpa-onnx/releases/download/vocoder-models/vocos-16khz-univ.onnx
git clone https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-tts-samples hf
mkdir -p ./hf/matcha/icefall-zh-en/mp3
./generate_samples.py
pushd hf
git pull
git add .
git commit -m 'add samples for matcha tts zh en'
git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/sherpa-onnx-tts-samples main
popd
rm -rf hf
ls -lh
- name: Run
shell: bash
run: |
cd scripts/matcha-tts/zh-en
curl -SL -O https://modelscope.cn/models/dengcunqin/matcha_tts_zh_en_20251010/resolve/master/model-steps-3.onnx
curl -SL -O https://modelscope.cn/models/dengcunqin/matcha_tts_zh_en_20251010/resolve/master/vocab_tts.txt
./generate_tokens.py
./generate_lexicon.py
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
- name: Collect results ${{ matrix.version }}
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
src=scripts/matcha-tts/zh-en
dst=matcha-icefall-zh-en
mkdir $dst
cp -a espeak-ng-data $dst/
cp -v $src/tokens.txt $dst
cp -v $src/lexicon.txt $dst
cp -v $src/model-steps-3.onnx $dst
cp -v $src/README.md $dst
cp -v $src/*.fst $dst
tar cjfv $dst.tar.bz2 $dst
ls -lh $dst.tar.bz2
- name: Publish to huggingface
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/matcha-icefall-zh-en huggingface
cd huggingface
rm -rf ./*
git fetch
git pull
git lfs track "cmn_dict"
git lfs track "ru_dict" af_dict ar_dict da_dict en_dict fa_dict hu_dict ia_dict it_dict lb_dict phondata ta_dict ur_dict yue_dict
cp -a ../matcha-icefall-zh-en/* ./
git lfs track "*.onnx"
git add .
ls -lh
git status
git commit -m "add models"
git push https://csukuangfj:$HF_TOKEN@huggingface.co/csukuangfj/matcha-icefall-zh-en 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: 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
+2 -1
View File
@@ -6,9 +6,10 @@ https://modelscope.cn/models/dengcunqin/matcha_tts_zh_en_20251010/summary
Note that you have to use
vocos-16khz-univ.onnx
You can download it from
You can download it from
https://modelscope.cn/models/dengcunqin/matcha_tts_zh_en_20251010/resolve/master/vocos-16khz-univ.onnx
or
https://github.com/k2-fsa/sherpa-onnx/releases/download/vocoder-models/vocos-16khz-univ.onnx
```
{'am': './model-steps-3.onnx', 'vocoder': './vocos-16khz-univ.onnx', 'tokens': './tokens.txt', 'lexicon': './lexicon.txt', 'text': '中英文合成测试. It supports both English 和中文合成', 'out_wav': 'generated.wav'}
+6 -5
View File
@@ -45,12 +45,13 @@ def main():
if key in user_defined:
continue
tokens = pinyin(key, style=Style.TONE3, neutral_tone_with_five=True)
for i in range(len(tokens)):
if tokens[i] == "shei2":
tokens[i] = "shui2"
if tokens[i][-1] not in ("1", "2", "3", "4", "5"):
tokens[i] += "1"
for i in range(len(tokens)):
if tokens[i][0] == "shei2":
tokens[i][0] = "shui2"
if tokens[i][0][-1] not in ("1", "2", "3", "4", "5"):
tokens[i][0] += "1"
flatten = [t[0] for t in tokens]
+40
View File
@@ -0,0 +1,40 @@
#!/usr/bin/env python3
# Copyright 2025 Xiaomi Corp. (authors: Fangjun Kuang)
"""
Generate samples for
https://k2-fsa.github.io/sherpa/onnx/tts/all/
"""
import sherpa_onnx
import soundfile as sf
config = sherpa_onnx.OfflineTtsConfig(
model=sherpa_onnx.OfflineTtsModelConfig(
matcha=sherpa_onnx.OfflineTtsMatchaModelConfig(
acoustic_model="matcha-icefall-zh-en/model-steps-3.onnx",
vocoder="vocos-16khz-univ.onnx",
lexicon="matcha-icefall-zh-en/lexicon.txt",
tokens="matcha-icefall-zh-en/tokens.txt",
data_dir="matcha-icefall-zh-en/espeak-ng-data",
),
num_threads=2,
),
max_num_sentences=1,
rule_fsts="./matcha-icefall-zh-en/phone-zh.fst,./matcha-icefall-zh-en/date-zh.fst,./matcha-icefall-zh-en/number-zh.fst",
)
if not config.validate():
raise ValueError("Please check your config")
tts = sherpa_onnx.OfflineTts(config)
text = "我最近在学习machine learning,希望能够在未来的artificial intelligence领域有所建树。在这次vocation中,我们计划去Paris欣赏埃菲尔铁塔和卢浮宫的美景。某某银行的副行长和一些行政领导表示,他们去过长江和长白山; 经济不断增长。开始数字测试。2025年12月4号,拨打110或者189202512043。123456块钱。在这个快速发展的时代,人工智能技术正在改变我们的生活方式。语音合成作为人工智能的重要应用之一,让机器能够用自然流畅的语音与人类进行交流。"
audio = tts.generate(text, sid=0, speed=1.0)
sf.write(
"./hf/matcha/icefall-zh-en/mp3/0.mp3",
audio.samples,
samplerate=audio.sample_rate,
)