diff --git a/build-ios.sh b/build-ios.sh index 9d25c0469..be61a5d85 100755 --- a/build-ios.sh +++ b/build-ios.sh @@ -39,96 +39,90 @@ echo "SHERPA_ONNXRUNTIME_INCLUDE_DIR $SHERPA_ONNXRUNTIME_INCLUDE_DIR" # The symbol _NSLog is not defined # -if [[ ! -f ./build/simulator_x86_64/lib/libsherpa-onnx-c-api.a ]]; then - cmake \ - -DBUILD_PIPER_PHONMIZE_EXE=OFF \ - -DBUILD_PIPER_PHONMIZE_TESTS=OFF \ - -DBUILD_ESPEAK_NG_EXE=OFF \ - -DBUILD_ESPEAK_NG_TESTS=OFF \ - -S .. \ - -DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \ - -DPLATFORM=SIMULATOR64 \ - -DENABLE_BITCODE=0 \ - -DENABLE_ARC=1 \ - -DENABLE_VISIBILITY=0 \ - -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_SHARED_LIBS=OFF \ - -DSHERPA_ONNX_ENABLE_PYTHON=OFF \ - -DSHERPA_ONNX_ENABLE_TESTS=OFF \ - -DSHERPA_ONNX_ENABLE_CHECK=OFF \ - -DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ - -DSHERPA_ONNX_ENABLE_JNI=OFF \ - -DSHERPA_ONNX_ENABLE_C_API=ON \ - -DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \ - -DDEPLOYMENT_TARGET=13.0 \ - -B build/simulator_x86_64 - - cmake --build build/simulator_x86_64 -j 4 --verbose -fi +cmake \ + -DBUILD_PIPER_PHONMIZE_EXE=OFF \ + -DBUILD_PIPER_PHONMIZE_TESTS=OFF \ + -DBUILD_ESPEAK_NG_EXE=OFF \ + -DBUILD_ESPEAK_NG_TESTS=OFF \ + -S .. \ + -DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \ + -DPLATFORM=SIMULATOR64 \ + -DENABLE_BITCODE=0 \ + -DENABLE_ARC=1 \ + -DENABLE_VISIBILITY=0 \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_SHARED_LIBS=OFF \ + -DSHERPA_ONNX_ENABLE_PYTHON=OFF \ + -DSHERPA_ONNX_ENABLE_TESTS=OFF \ + -DSHERPA_ONNX_ENABLE_CHECK=OFF \ + -DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ + -DSHERPA_ONNX_ENABLE_JNI=OFF \ + -DSHERPA_ONNX_ENABLE_C_API=ON \ + -DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \ + -DDEPLOYMENT_TARGET=13.0 \ + -B build/simulator_x86_64 + +cmake --build build/simulator_x86_64 -j 4 --verbose echo "Building for simulator (arm64)" -if [[ ! -f ./build/simulator_arm64/lib/libsherpa-onnx-c-api.a ]]; then - cmake \ - -DBUILD_PIPER_PHONMIZE_EXE=OFF \ - -DBUILD_PIPER_PHONMIZE_TESTS=OFF \ - -DBUILD_ESPEAK_NG_EXE=OFF \ - -DBUILD_ESPEAK_NG_TESTS=OFF \ - -S .. \ - -DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \ - -DPLATFORM=SIMULATORARM64 \ - -DENABLE_BITCODE=0 \ - -DENABLE_ARC=1 \ - -DENABLE_VISIBILITY=0 \ - -DCMAKE_BUILD_TYPE=Release \ - -DCMAKE_INSTALL_PREFIX=./install \ - -DBUILD_SHARED_LIBS=OFF \ - -DSHERPA_ONNX_ENABLE_PYTHON=OFF \ - -DSHERPA_ONNX_ENABLE_TESTS=OFF \ - -DSHERPA_ONNX_ENABLE_CHECK=OFF \ - -DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ - -DSHERPA_ONNX_ENABLE_JNI=OFF \ - -DSHERPA_ONNX_ENABLE_C_API=ON \ - -DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \ - -DDEPLOYMENT_TARGET=13.0 \ - -B build/simulator_arm64 - - cmake --build build/simulator_arm64 -j 4 --verbose -fi +cmake \ + -DBUILD_PIPER_PHONMIZE_EXE=OFF \ + -DBUILD_PIPER_PHONMIZE_TESTS=OFF \ + -DBUILD_ESPEAK_NG_EXE=OFF \ + -DBUILD_ESPEAK_NG_TESTS=OFF \ + -S .. \ + -DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \ + -DPLATFORM=SIMULATORARM64 \ + -DENABLE_BITCODE=0 \ + -DENABLE_ARC=1 \ + -DENABLE_VISIBILITY=0 \ + -DCMAKE_BUILD_TYPE=Release \ + -DCMAKE_INSTALL_PREFIX=./install \ + -DBUILD_SHARED_LIBS=OFF \ + -DSHERPA_ONNX_ENABLE_PYTHON=OFF \ + -DSHERPA_ONNX_ENABLE_TESTS=OFF \ + -DSHERPA_ONNX_ENABLE_CHECK=OFF \ + -DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ + -DSHERPA_ONNX_ENABLE_JNI=OFF \ + -DSHERPA_ONNX_ENABLE_C_API=ON \ + -DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \ + -DDEPLOYMENT_TARGET=13.0 \ + -B build/simulator_arm64 + +cmake --build build/simulator_arm64 -j 4 --verbose echo "Building for arm64" export SHERPA_ONNXRUNTIME_LIB_DIR=$PWD/ios-onnxruntime/onnxruntime.xcframework/ios-arm64 -if [[ ! -f ./build/os64/lib/libsherpa-onnx-c-api.a ]]; then - cmake \ - -DBUILD_PIPER_PHONMIZE_EXE=OFF \ - -DBUILD_PIPER_PHONMIZE_TESTS=OFF \ - -DBUILD_ESPEAK_NG_EXE=OFF \ - -DBUILD_ESPEAK_NG_TESTS=OFF \ - -S .. \ - -DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \ - -DPLATFORM=OS64 \ - -DENABLE_BITCODE=0 \ - -DENABLE_ARC=1 \ - -DENABLE_VISIBILITY=0 \ - -DCMAKE_INSTALL_PREFIX=./install \ - -DCMAKE_BUILD_TYPE=Release \ - -DBUILD_SHARED_LIBS=OFF \ - -DSHERPA_ONNX_ENABLE_PYTHON=OFF \ - -DSHERPA_ONNX_ENABLE_TESTS=OFF \ - -DSHERPA_ONNX_ENABLE_CHECK=OFF \ - -DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ - -DSHERPA_ONNX_ENABLE_JNI=OFF \ - -DSHERPA_ONNX_ENABLE_C_API=ON \ - -DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \ - -DDEPLOYMENT_TARGET=13.0 \ - -B build/os64 - - cmake --build build/os64 -j 4 - # Generate headers for sherpa-onnx.xcframework - cmake --build build/os64 --target install -fi +cmake \ + -DBUILD_PIPER_PHONMIZE_EXE=OFF \ + -DBUILD_PIPER_PHONMIZE_TESTS=OFF \ + -DBUILD_ESPEAK_NG_EXE=OFF \ + -DBUILD_ESPEAK_NG_TESTS=OFF \ + -S .. \ + -DCMAKE_TOOLCHAIN_FILE=./toolchains/ios.toolchain.cmake \ + -DPLATFORM=OS64 \ + -DENABLE_BITCODE=0 \ + -DENABLE_ARC=1 \ + -DENABLE_VISIBILITY=0 \ + -DCMAKE_INSTALL_PREFIX=./install \ + -DCMAKE_BUILD_TYPE=Release \ + -DBUILD_SHARED_LIBS=OFF \ + -DSHERPA_ONNX_ENABLE_PYTHON=OFF \ + -DSHERPA_ONNX_ENABLE_TESTS=OFF \ + -DSHERPA_ONNX_ENABLE_CHECK=OFF \ + -DSHERPA_ONNX_ENABLE_PORTAUDIO=OFF \ + -DSHERPA_ONNX_ENABLE_JNI=OFF \ + -DSHERPA_ONNX_ENABLE_C_API=ON \ + -DSHERPA_ONNX_ENABLE_WEBSOCKET=OFF \ + -DDEPLOYMENT_TARGET=13.0 \ + -B build/os64 + +cmake --build build/os64 -j 4 +# Generate headers for sherpa-onnx.xcframework +cmake --build build/os64 --target install echo "Generate xcframework" diff --git a/ios-swiftui/SherpaOnnxTts/SherpaOnnxTts/ViewModel.swift b/ios-swiftui/SherpaOnnxTts/SherpaOnnxTts/ViewModel.swift index 3e5c381c5..45db6ec17 100644 --- a/ios-swiftui/SherpaOnnxTts/SherpaOnnxTts/ViewModel.swift +++ b/ios-swiftui/SherpaOnnxTts/SherpaOnnxTts/ViewModel.swift @@ -93,12 +93,50 @@ func getTtsFor_en_US_amy_low() -> SherpaOnnxOfflineTtsWrapper { return SherpaOnnxOfflineTtsWrapper(config: &config) } +// https://k2-fsa.github.io/sherpa/onnx/tts/pretrained_models/vits.html#vits-melo-tts-zh-en-chinese-english-1-speaker +func getTtsFor_zh_en_melo_tts() -> SherpaOnnxOfflineTtsWrapper { + // please see https://github.com/k2-fsa/sherpa-onnx/releases/download/tts-models/vits-melo-tts-zh_en.tar.bz2 + + let model = getResource("model", "onnx") + + let tokens = getResource("tokens", "txt") + let lexicon = getResource("lexicon", "txt") + + let dictDir = resourceURL(to: "dict") + + let numFst = getResource("number", "fst") + let dateFst = getResource("date", "fst") + let phoneFst = getResource("phone", "fst") + let ruleFsts = "\(dateFst),\(phoneFst),\(numFst)" + + let vits = sherpaOnnxOfflineTtsVitsModelConfig( + model: model, lexicon: lexicon, tokens: tokens, + dataDir: "", + noiseScale: 0.667, + noiseScaleW: 0.8, + lengthScale: 1.0, + dictDir: dictDir + ) + + let modelConfig = sherpaOnnxOfflineTtsModelConfig(vits: vits) + var config = sherpaOnnxOfflineTtsConfig( + model: modelConfig, + ruleFsts: ruleFsts + ) + + return SherpaOnnxOfflineTtsWrapper(config: &config) +} + func createOfflineTts() -> SherpaOnnxOfflineTtsWrapper { + // Please enable only one of them + return getTtsFor_en_US_amy_low() // return getTtsForVCTK() // return getTtsForAishell3() + // return getTtsFor_zh_en_melo_tts() + // please add more models on need by following the above two examples }