### Setup Dart API Example Source: https://k2-fsa.github.io/sherpa/onnx/sense-voice/dart-api.html Navigate to the non-streaming ASR example directory within the cloned sherpa-onnx repository and fetch the necessary Dart packages using 'dart pub get'. ```bash cd sherpa-onnx cd dart-api-examples cd non-streaming-asr dart pub get ``` -------------------------------- ### Example installation logs Source: https://k2-fsa.github.io/sherpa/onnx/python/install.html Sample output showing the installation process and the downloading of wheels from Hugging Face. ```text Looking in links: https://k2-fsa.github.io/sherpa/onnx/cpu.html Collecting sherpa_onnx_bin Downloading https://huggingface.co/csukuangfj2/sherpa-onnx-wheels/resolve/main/cpu/1.13.7/sherpa_onnx_bin-1.13.7-py3-none-manylinux2014_x86_64.whl (21.6 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 21.6/21.6 MB 244.9 MB/s eta 0:00:00 Collecting sherpa_onnx_core Downloading https://huggingface.co/csukuangfj2/sherpa-onnx-wheels/resolve/main/cpu/1.13.7/sherpa_onnx_core-1.13.7-py3-none-manylinux2014_x86_64.whl (9.5 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 9.5/9.5 MB 207.6 MB/s eta 0:00:00 Collecting sherpa_onnx Downloading https://huggingface.co/csukuangfj2/sherpa-onnx-wheels/resolve/main/cpu/1.13.7/sherpa_onnx-1.13.7-cp312-cp312-manylinux2014_x86_64.manylinux_2_17_x86_64.whl (4.1 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 4.1/4.1 MB 149.8 MB/s eta 0:00:00 Installing collected packages: sherpa_onnx_core, sherpa_onnx_bin, sherpa_onnx ``` -------------------------------- ### Expected installation output Source: https://k2-fsa.github.io/sherpa/onnx/python/install.html This is an example of the file path output that should be displayed upon a successful installation. ```text /Users/fangjun/py38/lib/python3.8/site-packages/sherpa_onnx/__init__.py ``` -------------------------------- ### Installation logs for sherpa-onnx Source: https://k2-fsa.github.io/sherpa/onnx/python/install.html Example output showing the successful download and installation of the sherpa-onnx wheel. ```text Looking in links: https://k2-fsa.github.io/sherpa/onnx/cuda.html Collecting sherpa-onnx==1.13.7+cuda Downloading https://huggingface.co/csukuangfj2/sherpa-onnx-wheels/resolve/main/cuda/1.13.7/sherpa_onnx-1.13.7%2Bcuda-cp312-cp312-linux_x86_64.whl (190.3 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 190.3/190.3 MB 9.2 MB/s eta 0:00:00 Installing collected packages: sherpa-onnx ``` -------------------------------- ### Run the version example Source: https://k2-fsa.github.io/sherpa/onnx/rust-api/install.html Execute the version example to verify the installation. It should output the version, Git SHA1, and Git date. ```bash cargo run --example version ``` -------------------------------- ### sherpa-onnx-online-websocket-server Command Example Source: https://k2-fsa.github.io/sherpa/onnx/websocket/online-websocket.html An example command to start the websocket server with specified configurations for port, threads, model paths, and logging. ```bash ./bin/sherpa-onnx-online-websocket-server \ --port=6006 \ --num-work-threads=5 \ --tokens=/path/to/tokens.txt \ --encoder=/path/to/encoder.onnx \ --decoder=/path/to/decoder.onnx \ --joiner=/path/to/joiner.onnx \ --log-file=./log.txt \ --max-batch-size=5 \ --loop-interval-ms=10 ``` -------------------------------- ### Generate speech with vits-piper-sv_SE-alma-medium in Python Source: https://k2-fsa.github.io/sherpa/onnx/tts/all/Swedish/vits-piper-sv_SE-alma-medium.html Python example that loads the vits-piper-sv_SE-alma-medium model and synthesizes speech from the given text, saving the result as test.mp3. Requires the model to be downloaded and sherpa-onnx installed. ```python import sherpa_onnx import soundfile as sf config = sherpa_onnx.OfflineTtsConfig( model=sherpa_onnx.OfflineTtsModelConfig( vits=sherpa_onnx.OfflineTtsVitsModelConfig( model="vits-piper-sv_SE-alma-medium/sv_SE-alma-medium.onnx", data_dir="vits-piper-sv_SE-alma-medium/espeak-ng-data", tokens="vits-piper-sv_SE-alma-medium/tokens.txt", ), num_threads=1, ), ) if not config.validate(): raise ValueError("Please check your config") tts = sherpa_onnx.OfflineTts(config) audio = tts.generate(text="Liten skog, med många träd", sid=0, speed=1.0) sf.write("test.mp3", audio.samples, samplerate=audio.sample_rate) ``` -------------------------------- ### C API example for vits-piper-sv_SE-alma-medium Source: https://k2-fsa.github.io/sherpa/onnx/tts/all/Swedish/vits-piper-sv_SE-alma-medium.html C API example that generates speech with the vits-piper-sv_SE-alma-medium model and writes the audio to ./test.wav. It sets the model paths, generation config (sid=0, speed=1.0), and frees allocated resources to avoid memory leaks. ```c #include #include #include "sherpa-onnx/c-api/c-api.h" int main() { SherpaOnnxOfflineTtsConfig config; memset(&config, 0, sizeof(config)); config.model.vits.model = "vits-piper-sv_SE-alma-medium/sv_SE-alma-medium.onnx"; config.model.vits.tokens = "vits-piper-sv_SE-alma-medium/tokens.txt"; config.model.vits.data_dir = "vits-piper-sv_SE-alma-medium/espeak-ng-data"; config.model.num_threads = 1; // If you want to see debug messages, please set it to 1 config.model.debug = 0; const SherpaOnnxOfflineTts *tts = SherpaOnnxCreateOfflineTts(&config); const char *text = "Liten skog, med många träd"; SherpaOnnxGenerationConfig gen_cfg; memset(&gen_cfg, 0, sizeof(gen_cfg)); gen_cfg.sid = 0; gen_cfg.speed = 1.0; const SherpaOnnxGeneratedAudio *audio = SherpaOnnxOfflineTtsGenerateWithConfig(tts, text, &gen_cfg, NULL, NULL); SherpaOnnxWriteWave(audio->samples, audio->n, audio->sample_rate, "./test.wav"); // You need to free the pointers to avoid memory leak in your app SherpaOnnxDestroyOfflineTtsGeneratedAudio(audio); SherpaOnnxDestroyOfflineTts(tts); printf("Saved to ./test.wav\n"); return 0; } ``` -------------------------------- ### Kotlin supertonic-3 TTS example Source: https://k2-fsa.github.io/sherpa/onnx/tts/all/Vietnamese/supertonic-3-vi.html Complete Kotlin example to generate speech using the supertonic-3 model. It configures the model with int8 ONNX files, sets generation parameters (sid, numSteps, speed, lang='vi'), generates audio from Vietnamese text, saves it to test.wav, and releases resources. The callback function returns 1 to continue or 0 to stop. ```kotlin package com.k2fsa.sherpa.onnx fun main() { var config = OfflineTtsConfig( model = OfflineTtsModelConfig( supertonic = OfflineTtsSupertonicModelConfig( durationPredictor = "sherpa-onnx-supertonic-3-tts-int8-2026-05-11/duration_predictor.int8.onnx", textEncoder = "sherpa-onnx-supertonic-3-tts-int8-2026-05-11/text_encoder.int8.onnx", vectorEstimator = "sherpa-onnx-supertonic-3-tts-int8-2026-05-11/vector_estimator.int8.onnx", vocoder = "sherpa-onnx-supertonic-3-tts-int8-2026-05-11/vocoder.int8.onnx", ttsJson = "sherpa-onnx-supertonic-3-tts-int8-2026-05-11/tts.json", unicodeIndexer = "sherpa-onnx-supertonic-3-tts-int8-2026-05-11/unicode_indexer.bin", voiceStyle = "sherpa-onnx-supertonic-3-tts-int8-2026-05-11/voice.bin", ), numThreads = 2, debug = true, ), ) val tts = OfflineTts(config = config) val genConfig = GenerationConfig( sid = 0, numSteps = 8, speed = 1.0f, extra = mapOf("lang" to "vi"), ) val audio = tts.generateWithConfigAndCallback( text = "Đây là công cụ chuyển văn bản thành giọng nói sử dụng kaldi thế hệ tiếp theo", config = genConfig, callback = ::callback, ) audio.save(filename = "test.wav") tts.release() println("Saved to test.wav") } fun callback(samples: FloatArray): Int { // 1 means to continue // 0 means to stop return 1 } ``` -------------------------------- ### Generate speech with vits-piper-sv_SE-alma-medium in C++ Source: https://k2-fsa.github.io/sherpa/onnx/tts/all/Swedish/vits-piper-sv_SE-alma-medium.html C++ example that uses the sherpa-onnx C++ API to generate speech with the vits-piper-sv_SE-alma-medium model. It demonstrates a progress callback, configures the model, and writes the output to test.wav. The #if 0 branch shows how to generate without a callback. ```cpp #include #include #include #include "sherpa-onnx/c-api/cxx-api.h" static int32_t ProgressCallback(const float *samples, int32_t num_samples, float progress, void *arg) { fprintf(stderr, "Progress: %.3f%%\n", progress * 100); // return 1 to continue generating // return 0 to stop generating return 1; } int32_t main(int32_t argc, char *argv[]) { using namespace sherpa_onnx::cxx; // NOLINT OfflineTtsConfig config; config.model.vits.model = "vits-piper-sv_SE-alma-medium/sv_SE-alma-medium.onnx"; config.model.vits.tokens = "vits-piper-sv_SE-alma-medium/tokens.txt"; config.model.vits.data_dir = "vits-piper-sv_SE-alma-medium/espeak-ng-data"; config.model.num_threads = 1; // If you want to see debug messages, please set it to 1 config.model.debug = 0; std::string filename = "./test.wav"; std::string text = "Liten skog, med många träd"; auto tts = OfflineTts::Create(config); GenerationConfig gen_cfg; gen_cfg.sid = 0; gen_cfg.speed = 1.0; // larger -> faster in speech speed #if 0 // If you don't want to use a callback, then please enable this branch GeneratedAudio audio = tts.Generate(text, gen_cfg); #else GeneratedAudio audio = tts.Generate(text, gen_cfg, ProgressCallback); #endif WriteWave(filename, {audio.samples, audio.sample_rate}); fprintf(stderr, "Input text is: %s\n", text.c_str()); fprintf(stderr, "Speaker ID is: %d\n", gen_cfg.sid); fprintf(stderr, "Saved to: %s\n", filename.c_str()); return 0; } ``` -------------------------------- ### Install sherpa-onnx and generate Vietnamese speech with supertonic-3 Source: https://k2-fsa.github.io/sherpa/onnx/tts/all/Vietnamese/supertonic-3-vi.html Install sherpa-onnx and run the supertonic-3 TTS model for Vietnamese. The Python code configures the model with int8 ONNX files, sets generation parameters (sid=0, num_steps=8, speed=1.0, lang='vi'), generates speech from the given Vietnamese text, and writes the result to test.wav. ```bash pip install sherpa-onnx ``` ```python import sherpa_onnx import soundfile as sf tts_config = sherpa_onnx.OfflineTtsConfig( model=sherpa_onnx.OfflineTtsModelConfig( supertonic=sherpa_onnx.OfflineTtsSupertonicModelConfig( duration_predictor="sherpa-onnx-supertonic-3-tts-int8-2026-05-11/duration_predictor.int8.onnx", text_encoder="sherpa-onnx-supertonic-3-tts-int8-2026-05-11/text_encoder.int8.onnx", vector_estimator="sherpa-onnx-supertonic-3-tts-int8-2026-05-11/vector_estimator.int8.onnx", vocoder="sherpa-onnx-supertonic-3-tts-int8-2026-05-11/vocoder.int8.onnx", tts_json="sherpa-onnx-supertonic-3-tts-int8-2026-05-11/tts.json", unicode_indexer="sherpa-onnx-supertonic-3-tts-int8-2026-05-11/unicode_indexer.bin", voice_style="sherpa-onnx-supertonic-3-tts-int8-2026-05-11/voice.bin", ), debug=False, num_threads=2, provider="cpu", ), ) tts = sherpa_onnx.OfflineTts(tts_config) gen_config = sherpa_onnx.GenerationConfig() gen_config.sid = 0 gen_config.num_steps = 8 gen_config.speed = 1.0 gen_config.extra["lang"] = "vi" audio = tts.generate("Đây là công cụ chuyển văn bản thành giọng nói sử dụng kaldi thế hệ tiếp theo", gen_config) sf.write("test.wav", audio.samples, samplerate=audio.sample_rate) ``` -------------------------------- ### Rust API example for vits-piper-sv_SE-alma-medium Source: https://k2-fsa.github.io/sherpa/onnx/tts/all/Swedish/vits-piper-sv_SE-alma-medium.html Rust code to create an OfflineTts instance with the vits-piper-sv_SE-alma-medium model, generate speech from text, and save it to ./test.wav. It prints sample rate, number of speakers, and progress during generation. ```rust use sherpa_onnx::{ GenerationConfig, OfflineTts, OfflineTtsConfig, OfflineTtsVitsModelConfig, }; fn main() { let config = OfflineTtsConfig { model: sherpa_onnx::OfflineTtsModelConfig { vits: OfflineTtsVitsModelConfig { model: Some("vits-piper-sv_SE-alma-medium/sv_SE-alma-medium.onnx".into()), tokens: Some("vits-piper-sv_SE-alma-medium/tokens.txt".into()), data_dir: Some("vits-piper-sv_SE-alma-medium/espeak-ng-data".into()), ..Default::default() }, num_threads: 2, debug: false, ..Default::default() }, ..Default::default() }; let tts = OfflineTts::create(&config).expect("Failed to create OfflineTts"); println!("Sample rate: {}", tts.sample_rate()); println!("Num speakers: {}", tts.num_speakers()); let text = "Liten skog, med många träd"; let gen_config = GenerationConfig { sid: 0, speed: 1.0, ..Default::default() }; let audio = tts .generate_with_config( text, &gen_config, Some(|_samples: &[f32], progress: f32| -> bool { println!("Progress: {:.1}%", progress * 100.0); true }), ) .expect("Generation failed"); let filename = "./test.wav"; if audio.save(filename) { println!("Saved to: {}", filename); } else { eprintln!("Failed to save {}", filename); } } ``` -------------------------------- ### Generate speech with supertonic-3 using Rust API Source: https://k2-fsa.github.io/sherpa/onnx/tts/all/Vietnamese/supertonic-3-vi.html Rust example that creates an OfflineTts with the supertonic-3 model, generates speech from Vietnamese text, and saves the audio to test.wav. Uses GenerationConfig with sid 0, num_steps 8, speed 1.0, and extra JSON {"lang": "vi"}. Requires the model files in the current directory and the sherpa-onnx Rust crate. ```rust use sherpa_onnx::{ GenerationConfig, OfflineTts, OfflineTtsConfig, OfflineTtsSupertonicModelConfig, }; fn main() { let config = OfflineTtsConfig { model: sherpa_onnx::OfflineTtsModelConfig { supertonic: OfflineTtsSupertonicModelConfig { duration_predictor: Some("sherpa-onnx-supertonic-3-tts-int8-2026-05-11/duration_predictor.int8.onnx".into()), text_encoder: Some("sherpa-onnx-supertonic-3-tts-int8-2026-05-11/text_encoder.int8.onnx".into()), vector_estimator: Some("sherpa-onnx-supertonic-3-tts-int8-2026-05-11/vector_estimator.int8.onnx".into()), vocoder: Some("sherpa-onnx-supertonic-3-tts-int8-2026-05-11/vocoder.int8.onnx".into()), tts_json: Some("sherpa-onnx-supertonic-3-tts-int8-2026-05-11/tts.json".into()), unicode_indexer: Some("sherpa-onnx-supertonic-3-tts-int8-2026-05-11/unicode_indexer.bin".into()), voice_style: Some("sherpa-onnx-supertonic-3-tts-int8-2026-05-11/voice.bin".into()), ..Default::default() }, num_threads: 2, debug: false, ..Default::default() }, ..Default::default() }; let tts = OfflineTts::create(&config).expect("Failed to create OfflineTts"); println!("Sample rate: {}", tts.sample_rate()); println!("Num speakers: {}", tts.num_speakers()); let text = "Đây là công cụ chuyển văn bản thành giọng nói sử dụng kaldi thế hệ tiếp theo"; let gen_config = GenerationConfig { sid: 0, num_steps: 8, speed: 1.0, extra: Some(r#"{"lang": "vi"}"#.into()), ..Default::default() }; let audio = tts .generate_with_config( text, &gen_config, Some(|_samples: &[f32], progress: f32| -> bool { println!("Progress: {:.1}%", progress * 100.0); true }), ) .expect("Generation failed"); let filename = "./test.wav"; if audio.save(filename) { println!("Saved to: {}", filename); } else { eprintln!("Failed to save {}", filename); } } ``` -------------------------------- ### C#: Play vits-piper-sv_SE-alma-medium with OfflineTts Source: https://k2-fsa.github.io/sherpa/onnx/tts/all/Swedish/vits-piper-sv_SE-alma-medium.html Use the C# API to synthesize Swedish speech with the vits-piper-sv_SE-alma-medium model. Configure the model paths, set generation parameters (sid, speed, silenceScale), generate audio, and save it as a WAV file. The example prints success or failure messages. ```csharp using SherpaOnnx; var config = new OfflineTtsConfig(); config.Model.Vits.Model = "vits-piper-sv_SE-alma-medium/sv_SE-alma-medium.onnx"; config.Model.Vits.Tokens = "vits-piper-sv_SE-alma-medium/tokens.txt"; config.Model.Vits.DataDir = "vits-piper-sv_SE-alma-medium/espeak-ng-data"; config.Model.NumThreads = 1; config.Model.Debug = 1; config.Model.Provider = "cpu"; config.MaxNumSentences = 1; var tts = new OfflineTts(config); var text = "Liten skog, med många träd"; OfflineTtsGenerationConfig genConfig = new OfflineTtsGenerationConfig(); genConfig.Sid = 0; genConfig.Speed = 1.0f; genConfig.SilenceScale = 0.2f; var audio = tts.GenerateWithConfig(text, genConfig, null); var ok = audio.SaveToWaveFile("./test.wav"); if (ok) { Console.WriteLine("Saved to ./test.wav"); } else { Console.WriteLine("Failed to save ./test.wav"); } ``` -------------------------------- ### C# code to play with supertonic-3 Source: https://k2-fsa.github.io/sherpa/onnx/tts/all/Vietnamese/supertonic-3-vi.html Configures the supertonic-3 TTS model with int8 ONNX files, sets the voice style, and generates speech from Vietnamese text. The example uses the CPU provider, sets debug mode, and saves the generated audio to ./test.wav. ```csharp using SherpaOnnx; var config = new OfflineTtsConfig(); config.Model.Supertonic.DurationPredictor = "sherpa-onnx-supertonic-3-tts-int8-2026-05-11/duration_predictor.int8.onnx"; config.Model.Supertonic.TextEncoder = "sherpa-onnx-supertonic-3-tts-int8-2026-05-11/text_encoder.int8.onnx"; config.Model.Supertonic.VectorEstimator = "sherpa-onnx-supertonic-3-tts-int8-2026-05-11/vector_estimator.int8.onnx"; config.Model.Supertonic.Vocoder = "sherpa-onnx-supertonic-3-tts-int8-2026-05-11/vocoder.int8.onnx"; config.Model.Supertonic.TtsJson = "sherpa-onnx-supertonic-3-tts-int8-2026-05-11/tts.json"; config.Model.Supertonic.UnicodeIndexer = "sherpa-onnx-supertonic-3-tts-int8-2026-05-11/unicode_indexer.bin"; config.Model.Supertonic.VoiceStyle = "sherpa-onnx-supertonic-3-tts-int8-2026-05-11/voice.bin"; config.Model.NumThreads = 2; config.Model.Debug = 1; config.Model.Provider = "cpu"; var tts = new OfflineTts(config); var text = "Đây là công cụ chuyển văn bản thành giọng nói sử dụng kaldi thế hệ tiếp theo"; OfflineTtsGenerationConfig genConfig = new OfflineTtsGenerationConfig(); genConfig.Sid = 0; genConfig.NumSteps = 8; genConfig.Speed = 1.0f; genConfig.Extra = "{\"lang\": \"vi\"}"; var audio = tts.GenerateWithConfig(text, genConfig, null); var ok = audio.SaveToWaveFile("./test.wav"); if (ok) { Console.WriteLine("Saved to ./test.wav"); } else { Console.WriteLine("Failed to save ./test.wav"); } ``` -------------------------------- ### Build sherpa-onnx with GPU (CUDA 12.8, CUDNN 9, Linux x64) Source: https://k2-fsa.github.io/sherpa/onnx/install/linux.html Builds sherpa-onnx with GPU support for CUDA 12.8 and CUDNN 9 on Linux x64. Requires installing CUDA toolkit 12.x with CUDNN 9; otherwise you get errors at runtime. Refer to the k2 installation guide for CUDA/CUDNN installation. ```bash git clone https://github.com/k2-fsa/sherpa-onnx cd sherpa-onnx mkdir build cd build cmake -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DSHERPA_ONNX_ENABLE_GPU=ON .. make -j6 ``` -------------------------------- ### Run Version Example with Helper Script Source: https://k2-fsa.github.io/sherpa/onnx/rust-api/examples/version.html Execute the version example using the provided helper script. This is the recommended method for running examples. ```bash ./run-version.sh ``` -------------------------------- ### Locate installed NDK Source: https://k2-fsa.github.io/sherpa/onnx/android/build-sherpa-onnx.html Example path for the installed Android NDK directory. ```text /Users/fangjun/software/my-android/ndk/22.1.7171670 ``` -------------------------------- ### Dart Pub Get Output Example Source: https://k2-fsa.github.io/sherpa/onnx/sense-voice/dart-api.html Example output from the 'dart pub get' command, showing package resolution, download progress, and version information for sherpa_onnx and its platform-specific extensions. ```text (py38) fangjuns-MacBook-Pro:non-streaming-asr fangjun$ dart pub get Resolving dependencies... (1.2s) Downloading packages... (33.3s) collection 1.18.0 (1.19.0 available) lints 3.0.0 (4.0.0 available) material_color_utilities 0.8.0 (0.12.0 available) meta 1.12.0 (1.15.0 available) > sherpa_onnx 1.10.17 (was 1.9.29) + sherpa_onnx_android 1.10.17 + sherpa_onnx_ios 1.10.17 + sherpa_onnx_linux 1.10.17 + sherpa_onnx_macos 1.10.17 + sherpa_onnx_windows 1.10.17 Changed 6 dependencies! 4 packages have newer versions incompatible with dependency constraints. Try `dart pub outdated` for more information. ``` -------------------------------- ### Verify shared library setup Source: https://k2-fsa.github.io/sherpa/onnx/rust-api/advanced-install.html Run the version example with the shared feature enabled to verify the configuration. ```bash cd sherpa-onnx/rust-api-examples cargo run --no-default-features --features shared --example version ``` -------------------------------- ### Install sherpa-onnx-node package Source: https://k2-fsa.github.io/sherpa/onnx/javascript-api/examples/speech_enhancement.html Installs the sherpa-onnx-node npm package required to run the speech enhancement example. ```bash npm install sherpa-onnx-node ``` -------------------------------- ### Download and Unzip QNN SDK Source: https://k2-fsa.github.io/sherpa/onnx/qnn/download-qnn.html Commands to create a directory, navigate into it, download the SDK using wget, and then unzip the downloaded file. ```bash mkdir $HOME/qnn cd $HOME/qnn wget https://softwarecenter.qualcomm.com/api/download/software/sdks/Qualcomm_AI_Runtime_Community/All/2.40.0.251030/v2.40.0.251030.zip unzip v2.40.0.251030.zip ``` -------------------------------- ### Emscripten Version Output Example Source: https://k2-fsa.github.io/sherpa/onnx/tts/wasm/install-emscripten.html This is an example of the expected output when verifying the Emscripten installation using `emcc -v`. ```text emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.48 (e967e20b4727956a30592165a3c1cde5c67fa0a8) shared:INFO: (Emscripten: Running sanity checks) (py38) fangjuns-MacBook-Pro:open-source fangjun$ emcc -v emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 3.1.48 (e967e20b4727956a30592165a3c1cde5c67fa0a8) clang version 18.0.0 (https://github.com/llvm/llvm-project a54545ba6514802178cf7cf1c1dd9f7efbf3cde7) Target: wasm32-unknown-emscripten Thread model: posix InstalledDir: /Users/fangjun/open-source/emsdk/upstream/bin ``` -------------------------------- ### Compile C example with gcc Source: https://k2-fsa.github.io/sherpa/onnx/tts/all/English/vits-inflect-en-micro-v2.html Compiles the C example (saved as /tmp/test-inflect.c) against the installed sherpa-onnx shared libraries. ```bash gcc \ -I /tmp/sherpa-onnx/shared/include \ -L /tmp/sherpa-onnx/shared/lib \ -lsherpa-onnx-c-api \ -lonnxruntime \ -o /tmp/test-inflect \ /tmp/test-inflect.c ``` -------------------------------- ### Run C Example Source: https://k2-fsa.github.io/sherpa/onnx/tts/all/Albanian/vits-piper-sq_AL-edon-medium.html Commands to execute the compiled binary. ```bash cd /tmp # Assume you have downloaded the model and extracted it to /tmp ./test-piper ``` -------------------------------- ### Run microphone example Source: https://k2-fsa.github.io/sherpa/onnx/rust-api/advanced-install.html Enable the mic feature to run the streaming microphone example. ```bash cd sherpa-onnx/rust-api-examples cargo run --features mic --example streaming_zipformer_microphone -- --help ``` -------------------------------- ### Compile C example with gcc Source: https://k2-fsa.github.io/sherpa/onnx/tts/all/Arabic/vits-piper-ar_JO-kareem-low.html Compiles the C example (saved as /tmp/test-piper.c) against the installed sherpa-onnx shared library and onnxruntime. ```bash gcc -I /tmp/sherpa-onnx/shared/include -L /tmp/sherpa-onnx/shared/lib -lsherpa-onnx-c-api -lonnxruntime -o /tmp/test-piper /tmp/test-piper.c ``` -------------------------------- ### Run Compiled Example Source: https://k2-fsa.github.io/sherpa/onnx/tts/all/Albanian/vits-piper-sq_AL-edon-medium.html Change directory to run the compiled binary. ```bash cd /tmp ``` -------------------------------- ### Example library paths Source: https://k2-fsa.github.io/sherpa/onnx/rust-api/advanced-install.html Examples of valid paths for the SHERPA_ONNX_LIB_DIR environment variable. ```text /path/to/sherpa-onnx/build/install/lib /path/to/sherpa-onnx-v1.13.7-linux-x64-static-lib/lib ``` -------------------------------- ### sherpa-onnx-node Installation and Usage Source: https://k2-fsa.github.io/sherpa/onnx/tts/all/English/vits-piper-en_US-john-medium.html Installation and usage example for the sherpa-onnx-node package to run the VITS Piper TTS model en_US-john-medium. ```APIDOC ## [NPM] sherpa-onnx-node ### Description Install the `sherpa-onnx-node` npm package to use the VITS Piper TTS model `en_US-john-medium` with the Node.js addon API. ### Installation ``` npm install sherpa-onnx-node ``` ### Usage ```javascript const sherpa_onnx = require('sherpa-onnx-node'); function createOfflineTts() { const config = { model: { vits: { model: 'vits-piper-en_US-john-medium/en_US-john-medium.onnx', tokens: 'vits-piper-en_US-john-medium/tokens.txt', dataDir: 'vits-piper-en_US-john-medium/espeak-ng-data', }, debug: true, numThreads: 1, provider: 'cpu', }, maxNumSentences: 1, }; return new sherpa_onnx.OfflineTts(config); } const tts = createOfflineTts(); const text = 'Friends fell out often because life was changing so fast. The easiest thing in the world was to lose touch with someone.'; const generationConfig = new sherpa_onnx.GenerationConfig({ sid: 0, speed: 1.0, silenceScale: 0.2, }); let start = Date.now(); const audio = tts.generate({text, generationConfig}); let stop = Date.now(); const elapsed_seconds = (stop - start) / 1000; const duration = audio.samples.length / audio.sampleRate; const real_time_factor = elapsed_seconds / duration; console.log('Wave duration', duration.toFixed(3), 'seconds'); console.log('Elapsed', elapsed_seconds.toFixed(3), 'seconds'); console.log( `RTF = ${elapsed_seconds.toFixed(3)}/${duration.toFixed(3)} =`, real_time_factor.toFixed(3)); const filename = 'test.wav'; sherpa_onnx.writeWave( filename, {samples: audio.samples, sampleRate: audio.sampleRate}); console.log(`Saved to ${filename}`); ``` ### Notes - Refer to the Node.js addon API documentation for more details. ``` -------------------------------- ### Compile and Run C Example Source: https://k2-fsa.github.io/sherpa/onnx/tts/all/Catalan/vits-piper-ca_ES-upc_ona-medium.html Commands to build the sherpa-onnx library, compile the C example, and execute the generated binary. ```bash cd /tmp git clone https://github.com/k2-fsa/sherpa-onnx cd sherpa-onnx mkdir build-shared cd build-shared cmake -DSHERPA_ONNX_ENABLE_C_API=ON -DCMAKE_BUILD_TYPE=Release -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=/tmp/sherpa-onnx/shared .. make make install ``` ```bash gcc -I /tmp/sherpa-onnx/shared/include -L /tmp/sherpa-onnx/shared/lib -lsherpa-onnx-c-api -lonnxruntime -o /tmp/test-piper /tmp/test-piper.c ``` ```bash cd /tmp # Assume you have downloaded the model and extracted it to /tmp ./test-piper ``` ```bash # For Linux export LD_LIBRARY_PATH=/tmp/sherpa-onnx/shared/lib:$LD_LIBRARY_PATH ``` -------------------------------- ### Example Output and Configuration Source: https://k2-fsa.github.io/sherpa/onnx/pretrained_models/telespeech/models.html This shows the expected command-line arguments parsed into a configuration object and the JSON output for recognized speech, including text and timestamps. Note the potential discrepancy in 'feature_dim' in logs. ```text /Users/fangjun/open-source/sherpa-onnx/sherpa-onnx/csrc/parse-options.cc:Read:361 ./build/bin/sherpa-onnx-offline --telespeech-ctc=./sherpa-onnx-telespeech-ctc-int8-zh-2024-06-04/model.int8.onnx --tokens=./sherpa-onnx-telespeech-ctc-int8-zh-2024-06-04/tokens.txt --model-type=telespeech_ctc --num-threads=1 ./sherpa-onnx-telespeech-ctc-int8-zh-2024-06-04/test_wavs/3-sichuan.wav ./sherpa-onnx-telespeech-ctc-int8-zh-2024-06-04/test_wavs/4-tianjin.wav ./sherpa-onnx-telespeech-ctc-int8-zh-2024-06-04/test_wavs/5-henan.wav OfflineRecognizerConfig(feat_config=FeatureExtractorConfig(sampling_rate=16000, feature_dim=80, low_freq=20, high_freq=-400, dither=0), model_config=OfflineModelConfig(transducer=OfflineTransducerModelConfig(encoder_filename="", decoder_filename="", joiner_filename=""), paraformer=OfflineParaformerModelConfig(model=""), nemo_ctc=OfflineNemoEncDecCtcModelConfig(model=""), whisper=OfflineWhisperModelConfig(encoder="", decoder="", language="", task="transcribe", tail_paddings=-1), tdnn=OfflineTdnnModelConfig(model=""), zipformer_ctc=OfflineZipformerCtcModelConfig(model=""), wenet_ctc=OfflineWenetCtcModelConfig(model=""), telespeech_ctc="./sherpa-onnx-telespeech-ctc-int8-zh-2024-06-04/model.int8.onnx", tokens="./sherpa-onnx-telespeech-ctc-int8-zh-2024-06-04/tokens.txt", num_threads=1, debug=False, provider="cpu", model_type="telespeech_ctc", modeling_unit="cjkchar", bpe_vocab=""), lm_config=OfflineLMConfig(model="", scale=0.5), ctc_fst_decoder_config=OfflineCtcFstDecoderConfig(graph="", max_active=3000), decoding_method="greedy_search", max_active_paths=4, hotwords_file="", hotwords_score=1.5, blank_penalty=0) Creating recognizer ... Started Done! ./sherpa-onnx-telespeech-ctc-int8-zh-2024-06-04/test_wavs/3-sichuan.wav {"text": "自己就是在那个在那个就是在情界里面就是感觉演得特别好就是好像很真实样知道吧", "timestamps": [0.08, 0.36, 0.52, 0.72, 0.92, 1.16, 1.36, 1.88, 2.20, 2.36, 3.16, 3.28, 3.40, 3.60, 3.80, 3.92, 4.08, 4.24, 4.40, 4.56, 4.76, 5.16, 5.32, 5.44, 5.64, 5.76, 5.88, 6.04, 6.16, 6.28, 6.40, 6.60, 6.88, 7.12, 7.40, 7.52, 7.64], "tokens":["自", "己", "就", "是", "在", "那", "个", "在", "那", "个", "就", "是", "在", "情", "界", "里", "面", "就", "是", "感", "觉", "演", "得", "特", "别", "好", "就", "是", "好", "像", "很", "真", "实", "样", "知", "道", "吧"]} ---- ./sherpa-onnx-telespeech-ctc-int8-zh-2024-06-04/test_wavs/4-tianjin.wav {"text": "他就每个人手法就这意思法律意识太单薄了而且就是也不顾及到别人的感受", "timestamps": [0.36, 0.56, 1.04, 1.16, 1.24, 1.64, 1.88, 2.24, 2.40, 2.60, 2.80, 3.12, 3.32, 3.64, 3.80, 3.96, 4.16, 4.44, 4.68, 4.80, 5.00, 5.16, 5.28, 6.12, 6.28, 6.44, 6.60, 6.72, 6.88, 7.04, 7.12, 7.32, 7.52], "tokens":["他", "就", "每", "个", "人", "手", "法", "就", "这", "意", "思", "法", "律", "意", "识", "太", "单", "薄", "了", "而", "且", "就", "是", "也", "不", "顾", "及", "到", "别", "人", "的", "感", "受"]} ---- ./sherpa-onnx-telespeech-ctc-int8-zh-2024-06-04/test_wavs/5-henan.wav {"text": "他这个管一都通到有时候都通到七八层楼高然它这个管箱就可交到那个那珠子上", "timestamps": [0.04, 0.12, 0.24, 0.40, 1.00, 1.24, 1.44, 1.68, 2.32, 2.48, 2.60, 2.64, 2.80, 3.00, 3.16, 3.32, 3.52, 3.68, 3.92, 5.00, 5.16, 5.28, 5.32, 5.44, 5.84, 6.00, 6.12, 6.48, 6.68, 6.84, 7.00, 7.16, 7.32, 7.56, 7.68], "tokens":["他", "这", "个", "管", "一", "都", "通", "到", "有", "时", "候", "都", "通", "到", "七", "八", "层", "楼", "高", "然", "它", "这", "个", "管", "箱", "就", "可", "交", "到", "那", "个", "那", "珠", "子", "上"]} ---- num threads: 1 decoding method: greedy_search Elapsed seconds: 3.406 s Real time factor (RTF): 3.406 / 23.634 = 0.144 ```