diff --git a/.github/scripts/test-offline-tts.sh b/.github/scripts/test-offline-tts.sh new file mode 100755 index 000000000..3b6746509 --- /dev/null +++ b/.github/scripts/test-offline-tts.sh @@ -0,0 +1,72 @@ +#!/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 "EXE is $EXE" +echo "PATH: $PATH" + +which $EXE + +# test waves are saved in ./tts +mkdir ./tts + +log "vits-ljs test" + +wget -qq https://huggingface.co/csukuangfj/vits-ljs/resolve/main/vits-ljs.onnx +wget -qq https://huggingface.co/csukuangfj/vits-ljs/resolve/main/lexicon.txt +wget -qq https://huggingface.co/csukuangfj/vits-ljs/resolve/main/tokens.txt + +$EXE \ + --vits-model=./vits-ljs.onnx \ + --vits-lexicon=./lexicon.txt \ + --vits-tokens=./tokens.txt \ + --output-filename=./tts/vits-ljs.wav \ + 'liliana, the most beautiful and lovely assistant of our team!' + +ls -lh ./tts + +rm -v vits-ljs.onnx ./lexicon.txt ./tokens.txt + +log "vits-vctk test" +wget -qq https://huggingface.co/csukuangfj/vits-vctk/resolve/main/vits-vctk.onnx +wget -qq https://huggingface.co/csukuangfj/vits-vctk/resolve/main/lexicon.txt +wget -qq https://huggingface.co/csukuangfj/vits-vctk/resolve/main/tokens.txt + +for sid in 0 10 90; do + $EXE \ + --vits-model=./vits-vctk.onnx \ + --vits-lexicon=./lexicon.txt \ + --vits-tokens=./tokens.txt \ + --sid=$sid \ + --output-filename=./tts/vits-vctk-${sid}.wav \ + 'liliana, the most beautiful and lovely assistant of our team!' +done + +rm -v vits-vctk.onnx ./lexicon.txt ./tokens.txt +ls -lh tts/ + +log "vits-zh-aishell3" + +wget -qq https://huggingface.co/csukuangfj/vits-zh-aishell3/resolve/main/vits-aishell3.onnx +wget -qq https://huggingface.co/csukuangfj/vits-zh-aishell3/resolve/main/lexicon.txt +wget -qq https://huggingface.co/csukuangfj/vits-zh-aishell3/resolve/main/tokens.txt + +for sid in 0 10 90; do + $EXE \ + --vits-model=./vits-aishell3.onnx \ + --vits-lexicon=./lexicon.txt \ + --vits-tokens=./tokens.txt \ + --sid=$sid \ + --output-filename=./tts/vits-aishell3-${sid}.wav \ + '林美丽最美丽' +done + +rm -v vits-aishell3.onnx ./lexicon.txt ./tokens.txt + +ls -lh ./tts/ diff --git a/.github/workflows/linux-gpu.yaml b/.github/workflows/linux-gpu.yaml index de4e3e5af..db01420f3 100644 --- a/.github/workflows/linux-gpu.yaml +++ b/.github/workflows/linux-gpu.yaml @@ -12,6 +12,7 @@ on: - '.github/scripts/test-online-paraformer.sh' - '.github/scripts/test-offline-transducer.sh' - '.github/scripts/test-offline-ctc.sh' + - '.github/scripts/test-offline-tts.sh' - 'CMakeLists.txt' - 'cmake/**' - 'sherpa-onnx/csrc/*' @@ -26,6 +27,7 @@ on: - '.github/scripts/test-online-paraformer.sh' - '.github/scripts/test-offline-transducer.sh' - '.github/scripts/test-offline-ctc.sh' + - '.github/scripts/test-offline-tts.sh' - 'CMakeLists.txt' - 'cmake/**' - 'sherpa-onnx/csrc/*' @@ -48,7 +50,7 @@ jobs: build_type: [Release, Debug] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 @@ -75,6 +77,14 @@ jobs: file build/bin/sherpa-onnx readelf -d build/bin/sherpa-onnx + - name: Test offline TTS + shell: bash + run: | + export PATH=$PWD/build/bin:$PATH + export EXE=sherpa-onnx-offline-tts + + .github/scripts/test-offline-tts.sh + - name: Test online paraformer shell: bash run: | diff --git a/.github/workflows/linux.yaml b/.github/workflows/linux.yaml index 1bfb327ee..4fb48c4cf 100644 --- a/.github/workflows/linux.yaml +++ b/.github/workflows/linux.yaml @@ -12,6 +12,7 @@ on: - '.github/scripts/test-online-paraformer.sh' - '.github/scripts/test-offline-transducer.sh' - '.github/scripts/test-offline-ctc.sh' + - '.github/scripts/test-offline-tts.sh' - 'CMakeLists.txt' - 'cmake/**' - 'sherpa-onnx/csrc/*' @@ -26,6 +27,7 @@ on: - '.github/scripts/test-online-paraformer.sh' - '.github/scripts/test-offline-transducer.sh' - '.github/scripts/test-offline-ctc.sh' + - '.github/scripts/test-offline-tts.sh' - 'CMakeLists.txt' - 'cmake/**' - 'sherpa-onnx/csrc/*' @@ -49,7 +51,7 @@ jobs: shared_lib: [ON, OFF] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 @@ -76,6 +78,14 @@ jobs: file build/bin/sherpa-onnx readelf -d build/bin/sherpa-onnx + - name: Test offline TTS + shell: bash + run: | + export PATH=$PWD/build/bin:$PATH + export EXE=sherpa-onnx-offline-tts + + .github/scripts/test-offline-tts.sh + - name: Test online paraformer shell: bash run: | @@ -150,3 +160,8 @@ jobs: file_glob: true overwrite: true file: sherpa-onnx-*linux-x64.tar.bz2 + + - uses: actions/upload-artifact@v3 + with: + name: tts-generated-test-files + path: tts diff --git a/.github/workflows/macos.yaml b/.github/workflows/macos.yaml index 5cc6e83e2..721e1db3c 100644 --- a/.github/workflows/macos.yaml +++ b/.github/workflows/macos.yaml @@ -12,6 +12,7 @@ on: - '.github/scripts/test-online-paraformer.sh' - '.github/scripts/test-offline-transducer.sh' - '.github/scripts/test-offline-ctc.sh' + - '.github/scripts/test-offline-tts.sh' - 'CMakeLists.txt' - 'cmake/**' - 'sherpa-onnx/csrc/*' @@ -24,6 +25,7 @@ on: - '.github/scripts/test-online-paraformer.sh' - '.github/scripts/test-offline-transducer.sh' - '.github/scripts/test-offline-ctc.sh' + - '.github/scripts/test-offline-tts.sh' - 'CMakeLists.txt' - 'cmake/**' - 'sherpa-onnx/csrc/*' @@ -44,7 +46,7 @@ jobs: build_type: [Release, Debug] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 @@ -74,6 +76,14 @@ jobs: otool -L build/bin/sherpa-onnx otool -l build/bin/sherpa-onnx + - name: Test offline TTS + shell: bash + run: | + export PATH=$PWD/build/bin:$PATH + export EXE=sherpa-onnx-offline-tts + + .github/scripts/test-offline-tts.sh + - name: Test online paraformer shell: bash run: | diff --git a/.github/workflows/pkg-config.yaml b/.github/workflows/pkg-config.yaml index 6445ae5dc..4a898e373 100644 --- a/.github/workflows/pkg-config.yaml +++ b/.github/workflows/pkg-config.yaml @@ -9,6 +9,7 @@ on: - '*' paths: - '.github/workflows/pkg-config.yaml' + - '.github/scripts/test-offline-tts.sh' - 'CMakeLists.txt' - 'cmake/**' - 'sherpa-onnx/csrc/*' @@ -19,6 +20,7 @@ on: - master paths: - '.github/workflows/pkg-config.yaml' + - '.github/scripts/test-offline-tts.sh' - 'CMakeLists.txt' - 'cmake/**' - 'sherpa-onnx/csrc/*' @@ -92,9 +94,20 @@ jobs: run: | export PKG_CONFIG_PATH=$PWD/build/install:$PKG_CONFIG_PATH cd c-api-examples + gcc -o decode-file-c-api $(pkg-config --cflags sherpa-onnx) ./decode-file-c-api.c $(pkg-config --libs sherpa-onnx) ./decode-file-c-api --help + gcc -o offline-tts-c-api $(pkg-config --cflags sherpa-onnx) ./offline-tts-c-api.c $(pkg-config --libs sherpa-onnx) + ./offline-tts-c-api --help + + - name: Test offline TTS C API + shell: bash + run: | + export PATH=$PWD/c-api-examples:$PATH + export EXE=offline-tts-c-api + .github/scripts/test-offline-tts.sh + - name: Test online transducer (C API) shell: bash run: | @@ -102,3 +115,8 @@ jobs: export EXE=decode-file-c-api .github/scripts/test-online-transducer.sh + + - uses: actions/upload-artifact@v3 + with: + name: tts-generated-test-files + path: tts diff --git a/.github/workflows/windows-x64-cuda.yaml b/.github/workflows/windows-x64-cuda.yaml index afbb501c4..cd181fb12 100644 --- a/.github/workflows/windows-x64-cuda.yaml +++ b/.github/workflows/windows-x64-cuda.yaml @@ -12,6 +12,7 @@ on: - '.github/scripts/test-online-paraformer.sh' - '.github/scripts/test-offline-transducer.sh' - '.github/scripts/test-offline-ctc.sh' + - '.github/scripts/test-offline-tts.sh' - 'CMakeLists.txt' - 'cmake/**' - 'sherpa-onnx/csrc/*' @@ -24,6 +25,7 @@ on: - '.github/scripts/test-online-paraformer.sh' - '.github/scripts/test-offline-transducer.sh' - '.github/scripts/test-offline-ctc.sh' + - '.github/scripts/test-offline-tts.sh' - 'CMakeLists.txt' - 'cmake/**' - 'sherpa-onnx/csrc/*' @@ -64,6 +66,14 @@ jobs: ls -lh ./bin/Release/sherpa-onnx.exe + - name: Test offline TTS + shell: bash + run: | + export PATH=$PWD/build/bin/Release:$PATH + export EXE=sherpa-onnx-offline-tts.exe + + .github/scripts/test-offline-tts.sh + - name: Test online paraformer for windows x64 shell: bash run: | diff --git a/.github/workflows/windows-x64.yaml b/.github/workflows/windows-x64.yaml index c491b37d6..9e826f977 100644 --- a/.github/workflows/windows-x64.yaml +++ b/.github/workflows/windows-x64.yaml @@ -12,6 +12,7 @@ on: - '.github/scripts/test-online-paraformer.sh' - '.github/scripts/test-offline-transducer.sh' - '.github/scripts/test-offline-ctc.sh' + - '.github/scripts/test-offline-tts.sh' - 'CMakeLists.txt' - 'cmake/**' - 'sherpa-onnx/csrc/*' @@ -24,6 +25,7 @@ on: - '.github/scripts/test-online-paraformer.sh' - '.github/scripts/test-offline-transducer.sh' - '.github/scripts/test-offline-ctc.sh' + - '.github/scripts/test-offline-tts.sh' - 'CMakeLists.txt' - 'cmake/**' - 'sherpa-onnx/csrc/*' @@ -45,7 +47,7 @@ jobs: shared_lib: [ON, OFF] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 @@ -65,6 +67,14 @@ jobs: ls -lh ./bin/Release/sherpa-onnx.exe + - name: Test offline TTS + shell: bash + run: | + export PATH=$PWD/build/bin/Release:$PATH + export EXE=sherpa-onnx-offline-tts.exe + + .github/scripts/test-offline-tts.sh + - name: Test online paraformer for windows x64 shell: bash run: | diff --git a/.github/workflows/windows-x86.yaml b/.github/workflows/windows-x86.yaml index e74aa54b2..c6fa61ea2 100644 --- a/.github/workflows/windows-x86.yaml +++ b/.github/workflows/windows-x86.yaml @@ -12,6 +12,7 @@ on: - '.github/scripts/test-online-paraformer.sh' - '.github/scripts/test-offline-transducer.sh' - '.github/scripts/test-offline-ctc.sh' + - '.github/scripts/test-offline-tts.sh' - 'CMakeLists.txt' - 'cmake/**' - 'sherpa-onnx/csrc/*' @@ -24,6 +25,7 @@ on: - '.github/scripts/test-online-paraformer.sh' - '.github/scripts/test-offline-transducer.sh' - '.github/scripts/test-offline-ctc.sh' + - '.github/scripts/test-offline-tts.sh' - 'CMakeLists.txt' - 'cmake/**' - 'sherpa-onnx/csrc/*' @@ -45,7 +47,7 @@ jobs: shared_lib: [ON, OFF] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: fetch-depth: 0 @@ -65,6 +67,14 @@ jobs: ls -lh ./bin/Release/sherpa-onnx.exe + - name: Test offline TTS + shell: bash + run: | + export PATH=$PWD/build/bin/Release:$PATH + export EXE=sherpa-onnx-offline-tts.exe + + .github/scripts/test-offline-tts.sh + - name: Test online paraformer for windows x86 shell: bash run: | diff --git a/.gitignore b/.gitignore index b5b678525..cd68dd483 100644 --- a/.gitignore +++ b/.gitignore @@ -21,6 +21,7 @@ run-bilingual*.sh run-*-zipformer.sh run-zh.sh decode-file-c-api +offline-tts-c-api run-decode-file-c-api.sh sherpa-onnx-ffmpeg build-ios diff --git a/sherpa-onnx/c-api/c-api.cc b/sherpa-onnx/c-api/c-api.cc index b2e2c9198..6ea06fac8 100644 --- a/sherpa-onnx/c-api/c-api.cc +++ b/sherpa-onnx/c-api/c-api.cc @@ -15,6 +15,7 @@ #include "sherpa-onnx/csrc/offline-tts.h" #include "sherpa-onnx/csrc/online-recognizer.h" #include "sherpa-onnx/csrc/voice-activity-detector.h" +#include "sherpa-onnx/csrc/wave-writer.h" struct SherpaOnnxOnlineRecognizer { std::unique_ptr impl; @@ -585,3 +586,8 @@ SHERPA_ONNX_API void SherpaOnnxDestroyOfflineTtsGeneratedAudio( delete[] p->samples; delete p; } + +int32_t SherpaOnnxDestroyOfflineWriteWave(const SherpaOnnxGeneratedAudio *p, + const char *filename) { + return sherpa_onnx::WriteWave(filename, p->sample_rate, p->samples, p->n); +} diff --git a/sherpa-onnx/c-api/c-api.h b/sherpa-onnx/c-api/c-api.h index 54727ffe5..2898df30c 100644 --- a/sherpa-onnx/c-api/c-api.h +++ b/sherpa-onnx/c-api/c-api.h @@ -644,6 +644,13 @@ SHERPA_ONNX_API const SherpaOnnxGeneratedAudio *SherpaOnnxOfflineTtsGenerate( SHERPA_ONNX_API void SherpaOnnxDestroyOfflineTtsGeneratedAudio( const SherpaOnnxGeneratedAudio *p); +// Write the generated audio to a wave file. +// The saved wave file contains a single channel and has 16-bit samples. +// +// Return 1 if the write succeeded; return 0 on failure. +SHERPA_ONNX_API int32_t SherpaOnnxDestroyOfflineWriteWave( + const SherpaOnnxGeneratedAudio *p, const char *filename); + #if defined(__GNUC__) #pragma GCC diagnostic pop #endif diff --git a/sherpa-onnx/csrc/sherpa-onnx-offline-tts.cc b/sherpa-onnx/csrc/sherpa-onnx-offline-tts.cc index 6097468a2..835d09e34 100644 --- a/sherpa-onnx/csrc/sherpa-onnx-offline-tts.cc +++ b/sherpa-onnx/csrc/sherpa-onnx-offline-tts.cc @@ -40,7 +40,7 @@ wget https://huggingface.co/csukuangfj/vits-ljs/resolve/main/tokens.txt Please see https://k2-fsa.github.io/sherpa/onnx/tts/index.html -or detailes. +or details. )usage"; sherpa_onnx::ParseOptions po(kUsageMessage);