### Install Windows Build Dependencies Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md Installs required packages on Windows using winget for convenience. It specifically recommends installing Tar and Wget for handling archives and downloading files. ```console winget install -e --id GnuWin32.Tar winget install -e --id JernejSimoncic.Wget ``` -------------------------------- ### Configure Dynamic Libraries for GPU Examples (Linux) Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md When running examples that use dynamic libraries with GPU support (like DirectML or CUDA), ensure that the DLLs from the target folder are included in the system's PATH environment variable. ```console cargo build --features "directml" --example transcribe copy target\debug\examples\transcribe.exe target\debug target\debug\transcribe.exe motivation.wav ``` -------------------------------- ### Build for Windows ARM64 Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md Steps to build the project for Windows ARM64, which involves installing the ARM64 build tools in Visual Studio and then using the appropriate Rust target for building. ```console rustup target add aarch64-pc-windows-msvc cargo build --no-default-features --target aarch64-pc-windows-msvc --release ``` -------------------------------- ### Install Linux Build Dependencies Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md Installs necessary packages for building on Linux systems using apt-get. This includes pkg-config, build-essential, clang, and cmake. ```console sudo apt-get update sudo apt-get install -y pkg-config build-essential clang cmake ``` -------------------------------- ### Build for iOS (aarch64) Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md Instructions for building the project for iOS, including installing Xcode command line tools, adding necessary Rust targets for iOS and simulators, and setting RUSTFLAGS for linking. ```console xcode-select --install # IOS rustup target add aarch64-apple-ios # Intel chip emulator rustup target add x86_64-apple-ios # Apple chip emulator rustup target add aarch64-apple-ios-sim export RUSTFLAGS="-C link-arg=-fapple-link-rtlib" # See https://github.com/bmrlab/gendam/issues/96 cargo build --release --target aarch64-apple-ios ``` -------------------------------- ### Build Tauri Android Application with Sherpa-RS Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/examples/tauri-app/README.md This section details the environment variable setup for Android development, installing project dependencies using Bun, generating application icons, and configuring Cargo for Android builds using 'cargo-ndk'. It concludes with linking the compiled native libraries and starting the Android development server. ```bash # Setup environment variables export JAVA_HOME="/Applications/Android Studio.app/Contents/jbr/Contents/Home" export ANDROID_HOME="$HOME/Library/Android/sdk" export NDK_HOME="$HOME/Library/Android/sdk/ndk/27.0.12077973" # ls $HOME/Library/Android/sdk/ndk # Setup UI bun install bunx tauri icon src-tauri/icons/icon.png cd src-tauri export CARGO_TARGET_DIR="$(pwd)/target" cargo ndk -t arm64-v8a build mkdir -p gen/android/app/src/main/jniLibs/arm64-v8a ln -s $(pwd)/target/aarch64-linux-android/debug/libonnxruntime.so $(pwd)/gen/android/app/src/main/jniLibs/arm64-v8a/libonnxruntime.so ln -s $(pwd)/target/aarch64-linux-android/debug/libsherpa-onnx-c-api.so $(pwd)/gen/android/app/src/main/jniLibs/arm64-v8a/libsherpa-onnx-c-api.so bun run tauri android dev ``` -------------------------------- ### Build for Android (aarch64) Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md Steps to build the project for Android aarch64, including installing the necessary Rust target, Cargo NDK, setting the NDK_HOME environment variable, and executing the build command. ```console rustup target add aarch64-linux-android cargo install cargo-ndk export NDK_HOME="$HOME/Library/Android/sdk/ndk/27.0.12077973" # ls $HOME/Library/Android/sdk/ndk/ cargo ndk -t arm64-v8a build --release ``` -------------------------------- ### Speaker Diarization with Rust Source: https://context7.com/thewh1teagle/sherpa-rs/llms.txt Performs speaker diarization to segment and cluster speech segments by different speakers in an audio file. It requires pre-trained ONNX models for segmentation and speaker recognition. The function takes audio samples and an optional progress callback, returning a list of speaker segments with start and end times. ```rust use sherpa_rs::{diarize, read_audio_file}; fn main() { // Configure diarization let config = diarize::DiarizeConfig { num_clusters: Some(5), ..Default::default() }; // Progress callback for monitoring let progress_callback = |n_computed_chunks: i32, n_total_chunks: i32| -> i32 { let progress = 100 * n_computed_chunks / n_total_chunks; println!("Diarizing... {}%", progress); 0 }; // Create diarization engine let mut sd = diarize::Diarize::new( "sherpa-onnx-pyannote-segmentation-3-0/model.onnx", "3dspeaker_speech_eres2net_base_sv_zh-cn_3dspeaker_16k.onnx", config ).unwrap(); // Process audio file let (samples, _) = read_audio_file("0-four-speakers-zh.wav").unwrap(); let segments = sd.compute(samples, Some(Box::new(progress_callback))).unwrap(); // Display speaker segments for segment in segments { println!( "start = {:.2}s end = {:.2}s speaker = {}", segment.start, segment.end, segment.speaker ); } } ``` -------------------------------- ### Compile with Prebuilt Sherpa-onnx (Windows) Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md Compiles sherpa-rs using pre-downloaded static sherpa-onnx binaries for faster compilation on Windows (x86-64). It downloads, extracts, and sets the library path using PowerShell syntax. ```console wget.exe https://github.com/k2-fsa/sherpa-onnx/releases/download/v1.10.28/sherpa-onnx-v1.10.28-win-x64-static.tar.bz2 tar.exe xf sherpa-onnx-v1.10.28-win-x64-static.tar.bz2 $env:SHERPA_LIB_PATH="$pwd/sherpa-onnx-v1.10.28-win-x64-static" cargo build ``` -------------------------------- ### Create GitHub Release Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md This command uses the GitHub CLI to create a new release, automatically generating release notes based on commit history. ```console gh release create v0.4.1 --title v0.4.1 --generate-notes ``` -------------------------------- ### Inspect Build Output for Linking Flags (Windows) Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md To diagnose linking issues on Windows, set the RUSTC_LOG environment variable and build with verbose output. Pipe the output to a file to easily search for '/MD' (dynamic linking) and '/MT' or '-MT' (static linking) flags. ```console RUSTC_LOG=rustc_codegen_ssa::back::link=info cargo build -vv > log.txt 2>&1 ``` -------------------------------- ### Compile with Prebuilt Sherpa-onnx (Linux) Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md Compiles sherpa-rs using pre-downloaded static sherpa-onnx binaries for faster compilation on Linux (x86-64). It downloads, extracts, sets the library path, and configures RUSTFLAGS for static linking. ```console wget https://github.com/k2-fsa/sherpa-onnx/releases/download/v1.10.28/sherpa-onnx-v1.10.28-linux-x64-static.tar.bz2 tar xf sherpa-onnx-v1.10.28-linux-x64-static.tar.bz2 export SHERPA_LIB_PATH="$(pwd)/sherpa-onnx-v1.10.28-linux-x64-static" export RUSTFLAGS="-C relocation-model=dynamic-no-pic" cargo build ``` -------------------------------- ### Clone and Prepare Sherpa-rs Repository Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md Clones the sherpa-rs repository and its submodules recursively. This command ensures that all necessary dependencies are fetched. ```console git clone --recursive https://github.com/thewh1teagle/sherpa-rs cd sherpa-rs ``` -------------------------------- ### Compile with Prebuilt Sherpa-onnx (macOS) Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md Compiles sherpa-rs using pre-downloaded static sherpa-onnx binaries for faster compilation on macOS (arm64/x86-64). It downloads, extracts, sets the library path, and then builds. ```console wget https://github.com/k2-fsa/sherpa-onnx/releases/download/v1.10.28/sherpa-onnx-v1.10.28-osx-universal2-static.tar.bz2 tar xf sherpa-onnx-v1.10.28-osx-universal2-static.tar.bz2 export SHERPA_LIB_PATH="$(pwd)/sherpa-onnx-v1.10.28-osx-universal2-static" cargo build ``` -------------------------------- ### Configure Static Linking for Windows Builds Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md To resolve static linking failures on Windows, you can either create a `.cargo/config.toml` file with specific rustflags or set the RUSTFLAGS environment variable. This ensures the MSVC runtime is linked statically. ```toml [target.'cfg(windows)'] rustflags = ["-C target-feature=+crt-static"] ``` ```console RUSTFLAGS="-C target-feature=+crt-static" cargo build ``` -------------------------------- ### Linux Build Configuration Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md For Linux builds, set the RUSTFLAGS environment variable to specify the relocation model. This is important for dynamic linking. ```console RUSTFLAGS="-C relocation-model=dynamic-no-pic" ``` -------------------------------- ### Prepare Sherpa-ONNX Model for Tauri Application Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/examples/tauri-app/README.md This process downloads, extracts, and moves the necessary Sherpa-ONNX model files into the project's source directory. It then pushes the model to the Android device's temporary storage, which is currently hardcoded in the APK. ```bash cd src-tauri wget https://github.com/k2-fsa/sherpa-onnx/releases/download/punctuation-models/sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12.tar.bz2 tar xvf sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12.tar.bz2 mv sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12/model.onnx model.onnx rm -rf rm sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12 rm sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12.tar.bz2 adb push model.onnx /data/local/tmp/model.onnx # currently hardcoded in the APK ``` -------------------------------- ### View Detailed Build Debug Log Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md Combines enabling debug build logs with verbose output to capture detailed information about the build process. ```console SHERPA_BUILD_DEBUG=1 cargo build -vv ``` -------------------------------- ### Build Sherpa-rs Project Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md Compiles the sherpa-rs project in release mode using Cargo. This command optimizes the build for performance. ```console cargo build --release ``` -------------------------------- ### Build Flags Control Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md Control build flags by examining `env::var` calls within the `build.rs` file. This allows for dynamic configuration of the build process. ```rust // Example: env::var("SOME_FLAG").is_ok() ``` -------------------------------- ### Text-to-Speech with VITS in Rust Source: https://context7.com/thewh1teagle/sherpa-rs/llms.txt Generates natural-sounding speech from text using VITS (Variational Inference with adversarial learning for end-to-end Text-to-Speech) models. Requires ONNX models for the VITS TTS engine, a lexicon, and tokens. Outputs audio samples that can be saved to a WAV file. ```rust use sherpa_rs::tts::{VitsTts, VitsTtsConfig}; use sherpa_rs::write_audio_file; fn main() { // Configure VITS TTS model let config = VitsTtsConfig { model: "./vits-ljs.onnx".into(), lexicon: "./lexicon.txt".into(), tokens: "./tokens.txt".into(), length_scale: 1.0, ..Default::default() }; // Create TTS engine let mut tts = VitsTts::new(config); // Generate audio (sid = speaker ID, speed = 1.0) let audio = tts .create("Hello! This audio generated by onnx model!", 0, 1.0) .unwrap(); // Save to WAV file write_audio_file("audio.wav", &audio.samples, audio.sample_rate).unwrap(); println!("Created audio.wav with sample rate: {}", audio.sample_rate); } ``` -------------------------------- ### Calculate SHA256 Checksum (macOS) Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md This command calculates the SHA256 checksum for a given file on macOS and converts the output to uppercase. ```console shasum -a 256 | tr 'a-z' 'A-Z' ``` -------------------------------- ### Rust: Voice Activity Detection with Silero VAD and Speaker ID Source: https://context7.com/thewh1teagle/sherpa-rs/llms.txt This snippet demonstrates real-time voice activity detection (VAD) using the Silero VAD model and integrates it with speaker identification. It processes audio in segments, detects speech, extracts speaker embeddings, and identifies speakers in real-time. Dependencies include Silero VAD model, speaker embedding model, and appropriate audio handling. ```rust use sherpa_rs::{ silero_vad::{SileroVad, SileroVadConfig}, speaker_id::{EmbeddingExtractor, ExtractorConfig}, embedding_manager::EmbeddingManager, read_audio_file, }; fn main() { let (mut samples, sample_rate) = read_audio_file("motivation.wav").unwrap(); assert_eq!(sample_rate, 16000); // Pad with silence for proper VAD detection samples.extend(vec![0.0; (3 * sample_rate) as usize]); // Configure VAD with Silero model let window_size = 512; let vad_config = SileroVadConfig { model: "silero_vad.onnx".into(), window_size: window_size as i32, min_silence_duration: 0.5, min_speech_duration: 0.5, threshold: 0.5, ..Default::default() }; let mut vad = SileroVad::new(vad_config, 60.0 * 10.0).unwrap(); // Setup speaker identification let extractor_config = ExtractorConfig { model: "nemo_en_speakerverification_speakernet.onnx".into(), ..Default::default() }; let mut extractor = EmbeddingExtractor::new(extractor_config).unwrap(); let mut embedding_manager = EmbeddingManager::new(extractor.embedding_size.try_into().unwrap()); // Process audio in windows let mut index = 0; while index + window_size <= samples.len() { let window = &samples[index..index + window_size]; vad.accept_waveform(window.to_vec()); if vad.is_speech() { while !vad.is_empty() { let segment = vad.front(); let start_sec = (segment.start as f32) / sample_rate as f32; let duration_sec = (segment.samples.len() as f32) / sample_rate as f32; // Identify speaker let embedding = extractor .compute_speaker_embedding(segment.samples, sample_rate) .unwrap(); let speaker = embedding_manager .search(&embedding, 0.5) .unwrap_or_else(|| { let name = format!("speaker_{}", embedding_manager.num_speakers()); embedding_manager.add(name.clone(), &mut embedding.clone()).unwrap(); name }); println!("({}) start={}s end={}s", speaker, start_sec, start_sec + duration_sec); vad.pop(); } } index += window_size; } vad.flush(); } ``` -------------------------------- ### Enable Debug Build for Sherpa-ONNX Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md To enable debug logging during the build process of sherpa-onnx, set the SHERPA_BUILD_DEBUG environment variable to 1. ```console SHERPA_BUILD_DEBUG=1 cargo build ``` -------------------------------- ### Keyword Spotting with Rust Source: https://context7.com/thewh1teagle/sherpa-rs/llms.txt Enables keyword spotting in audio streams, detecting specific keywords or wake words. It uses Zipformer-based models and requires configurations for the encoder, decoder, joiner, tokens, and keywords. The function processes audio samples and returns the detected keyword or 'None detected'. ```rust use sherpa_rs::{keyword_spot, read_audio_file}; fn main() { let (samples, sample_rate) = read_audio_file("test_audio.wav").unwrap(); // Configure keyword spotting with Zipformer model let config = keyword_spot::KeywordSpotConfig { zipformer_encoder: "encoder-epoch-12-avg-2-chunk-16-left-64.int8.onnx".into(), zipformer_decoder: "decoder-epoch-12-avg-2-chunk-16-left-64.int8.onnx".into(), zipformer_joiner: "joiner-epoch-12-avg-2-chunk-16-left-64.int8.onnx".into(), tokens: "tokens.txt".into(), keywords: "test_keywords.txt".into(), max_active_path: 4, keywords_threshold: 0.1, keywords_score: 3.0, num_trailing_blanks: 1, sample_rate: 16000, feature_dim: 80, ..Default::default() }; let mut spotter = keyword_spot::KeywordSpot::new(config).unwrap(); // Extract detected keyword let keyword = spotter .extract_keyword(samples, sample_rate) .unwrap() .unwrap_or("None detected".into()); println!("Detected keyword: {}", keyword); } ``` -------------------------------- ### Rust: Identify Speakers using Embeddings Source: https://context7.com/thewh1teagle/sherpa-rs/llms.txt This snippet demonstrates how to identify and distinguish between different speakers in multiple audio files using pre-computed speaker embeddings. It requires audio files and a pre-trained speaker embedding model. The output is a map associating speaker IDs with the files they appear in. ```rust use sherpa_rs::{embedding_manager, speaker_id, read_audio_file}; use std::collections::HashMap; fn main() { let audio_files = vec!["obama.wav", "biden.wav"]; // Configure speaker embedding extractor let config = speaker_id::ExtractorConfig { model: "nemo_en_speakerverification_speakernet.onnx".into(), ..Default::default() }; let mut extractor = speaker_id::EmbeddingExtractor::new(config).unwrap(); // Compute embeddings for each audio file let mut embeddings = Vec::new(); for file in &audio_files { let (samples, sample_rate) = read_audio_file(file).unwrap(); assert_eq!(sample_rate, 16000); let embedding = extractor .compute_speaker_embedding(samples, sample_rate) .unwrap(); embeddings.push((file.to_string(), embedding)); } // Create embedding manager for speaker matching let mut embedding_manager = embedding_manager::EmbeddingManager::new(extractor.embedding_size.try_into().unwrap()); let mut speaker_map: HashMap> = HashMap::new(); let mut speaker_counter = 0; // Match speakers using similarity threshold for (file, embedding) in &embeddings { if let Some(speaker_name) = embedding_manager.search(embedding, 0.5) { // Matched existing speaker speaker_map.entry(speaker_name).or_default().push(file.clone()); } else { // Register new speaker embedding_manager .add(format!("speaker {}", speaker_counter), &mut embedding.clone()) .unwrap(); speaker_map .entry(format!("speaker {}", speaker_counter)) .or_default() .push(file.clone()); speaker_counter += 1; } } // Display results for (speaker_id, files) in &speaker_map { println!("Speaker {}: {:?}", speaker_id, files); } } ``` -------------------------------- ### Read and Write Audio Files with Sherpa-RS Source: https://context7.com/thewh1teagle/sherpa-rs/llms.txt Handles reading and writing 16kHz mono WAV audio files using the sherpa-rs library. It expects specific audio formats (16kHz, mono, PCM 16-bit) for reading and outputs processed audio to a WAV file. ```rust use sherpa_rs::{read_audio_file, write_audio_file}; fn main() { // Read audio file (must be 16kHz, mono, PCM 16-bit) let (samples, sample_rate) = read_audio_file("input.wav").unwrap(); assert_eq!(sample_rate, 16000, "Sample rate must be 16000Hz"); // samples is Vec with normalized values in range [-1.0, 1.0] println!("Loaded {} samples", samples.len()); // Process audio... let processed_samples = samples.iter().map(|&s| s * 0.5).collect::>(); // Write audio file write_audio_file("output.wav", &processed_samples, sample_rate).unwrap(); println!("Saved processed audio"); } ``` -------------------------------- ### Update Sherpa-onnx Git Repository Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md Updates the local sherpa-onnx repository to the latest changes from the master branch and checks out a specific new tag. This ensures the project uses the most recent version of sherpa-onnx. ```console cd sys/sherpa-onnx git pull origin master git checkout ``` -------------------------------- ### Debug Tauri Webview Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/examples/tauri-app/README.md Instructions for debugging the webview of a Tauri application by opening the Chrome inspect tool and connecting to the target webview. ```text Open `chrome://inspect` in the chrome browser and click `inspect` ``` -------------------------------- ### Enable Long Paths on Windows Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md Resolves CMake errors related to maximum path length exceeded on Windows. This involves modifying the Windows Registry to enable long path support and then restarting the computer. ```powershell New-ItemProperty -Path "HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem" ` -Name "LongPathsEnabled" -Value 1 -PropertyType DWORD -Force ``` -------------------------------- ### Speech Recognition with Whisper in Rust Source: https://context7.com/thewh1teagle/sherpa-rs/llms.txt Transcribes audio files using OpenAI Whisper models for automatic speech recognition. Requires audio files and pre-trained ONNX models for the decoder, encoder, and tokens. Outputs the transcribed text and additional metadata. ```rust use sherpa_rs::{ read_audio_file, whisper::{WhisperConfig, WhisperRecognizer}, }; fn main() { // Read 16kHz audio file let (samples, sample_rate) = read_audio_file("motivation.wav").unwrap(); assert_eq!(sample_rate, 16000, "The sample rate must be 16000."); // Configure Whisper model let config = WhisperConfig { decoder: "sherpa-onnx-whisper-tiny/tiny-decoder.onnx".into(), encoder: "sherpa-onnx-whisper-tiny/tiny-encoder.onnx".into(), tokens: "sherpa-onnx-whisper-tiny/tiny-tokens.txt".into(), language: "en".into(), provider: Some("cpu".into()), num_threads: Some(1), bpe_vocab: None, ..Default::default() }; // Create recognizer and transcribe let mut recognizer = WhisperRecognizer::new(config).unwrap(); let result = recognizer.transcribe(sample_rate, &samples); println!("Transcribed text: {}", result.text); // Result includes: text, language, timestamps, tokens } ``` -------------------------------- ### Resample WAV File to 16kHz Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md Uses FFmpeg to resample an input WAV file to 16kHz with a single audio channel (mono) and 16-bit PCM encoding. This is useful for preparing audio data for speech processing models. ```console ffmpeg -i -ar 16000 -ac 1 -c:a pcm_s16le ``` -------------------------------- ### Classify Audio Events with Sherpa-RS Source: https://context7.com/thewh1teagle/sherpa-rs/llms.txt Classifies audio events and environmental sounds in audio files using the sherpa-rs library. It requires audio files and model configurations for audio tagging. The output is a list of detected event labels. ```rust use sherpa_rs::{audio_tag, read_audio_file}; fn main() { let (samples, sample_rate) = read_audio_file("test_audio.wav").unwrap(); // Configure audio tagging model let config = audio_tag::AudioTagConfig { model: "sherpa-onnx-zipformer-audio-tagging-2024-04-09/model.int8.onnx".into(), labels: "sherpa-onnx-zipformer-audio-tagging-2024-04-09/class_labels_indices.csv".into(), top_k: 5, ..Default::default() }; let mut audio_tag = audio_tag::AudioTag::new(config).unwrap(); // Classify audio events let events = audio_tag.compute(samples, sample_rate); println!("Detected events ({}): {}", events.len(), events.join(", ")); // Example output: ["Speech", "Music", "Singing", "Background noise", "Crowd"] } ``` -------------------------------- ### Tauri App Styling (CSS) Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/examples/tauri-app/index.html CSS styles for the tauri application in sherpa-rs, focusing on a gradient background for headers and styling for input fields, buttons, and output areas. These styles are intended for web-based UI elements within the Tauri framework. ```css h1 { background-color: #8EC5FC; background-image: linear-gradient(62deg, #8EC5FC 0%, #E0C3FC 100%); -webkit-background-clip: text; /* Safari */ background-clip: text; /* For other modern browsers */ color: transparent; /* Make the text itself transparent */ } #input { width: 90%; height: 120px; border-radius: 12px; padding: 5px 5px; } .action { display: flex; justify-content: center; margin-top: 10px; } button { background: #8EC5FC; color: white; border: none; padding: 5px 5px; font-size: 22px; border-radius: 12px; } #output { margin-top: 20px; padding: 10px; border-radius: 12px; background-color: #f4f4f9; font-size: 18px; color: #333; word-wrap: break-word; } ``` -------------------------------- ### Bypass Checksum Validation Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md If you encounter checksum validation errors and trust the download source, you can bypass the validation process by setting the UNSAFE_DISABLE_CHECKSUM_VALIDATION environment variable to 1. ```console UNSAFE_DISABLE_CHECKSUM_VALIDATION=1 cargo build ``` -------------------------------- ### Text Punctuation with Rust Source: https://context7.com/thewh1teagle/sherpa-rs/llms.txt Adds punctuation marks to raw text transcripts automatically. It utilizes a transformer-based model for punctuation. The function takes a string as input and returns the punctuated text. Multiple sentences can be processed sequentially. ```rust use sherpa_rs::punctuate::{Punctuation, PunctuationConfig}; fn main() { // Configure punctuation model let config = PunctuationConfig { model: "sherpa-onnx-punct-ct-transformer-zh-en-vocab272727-2024-04-12/model.onnx".into(), ..Default::default() }; let mut punctuate = Punctuation::new(config).unwrap(); // Process text without punctuation let sentences = [ "这是一个测试你好吗How are you我很好thank you are you ok谢谢你", "我们都是木头人不会说话不会动", "The African blogosphere is rapidly expanding bringing more voices online in the form of commentaries opinions analyses rants and poetry" ]; for sentence in sentences { let punctuated = punctuate.add_punctuation(sentence); println!("Input: {}", sentence); println!("Output: {}", punctuated); println!("--------------------",); } } ``` -------------------------------- ### Debug Tauri Android Application Logs Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/examples/tauri-app/README.md This command clears the Android logcat buffer and then streams logs, filtering for messages related to 'tauri', 'rust', or 'sherpa' with case-insensitive matching. ```bash adb logcat -c && adb logcat | grep -i -E "tauri|rust|sherpa" ``` -------------------------------- ### Set RPATH for Shared Libraries (Linux) Source: https://github.com/thewh1teagle/sherpa-rs/blob/main/BUILDING.md This command modifies the shared library or binary to load other shared libraries located in the same folder as the executable. It's useful when encountering 'Shared library not found' errors on Linux. ```console patchelf --set-rpath '$ORIGIN' /path/to/binary/or/shared/library.so ``` -------------------------------- ### Spoken Language Identification with Rust Source: https://context7.com/thewh1teagle/sherpa-rs/llms.txt Identifies the spoken language in an audio file using Whisper-based models. It requires encoder and decoder ONNX models for the Whisper ASR system. The function takes audio samples and sample rate, returning a string representing the detected language code (e.g., 'en', 'zh'). ```rust use sherpa_rs::{language_id, read_audio_file}; fn main() { let (samples, sample_rate) = read_audio_file("16hz_mono_pcm_s16le.wav").unwrap(); assert_eq!(sample_rate, 16000); // Configure language identification model let config = language_id::SpokenLanguageIdConfig { encoder: "sherpa-onnx-whisper-tiny/tiny-encoder.onnx".into(), decoder: "sherpa-onnx-whisper-tiny/tiny-decoder.onnx".into(), ..Default::default() }; let mut extractor = language_id::SpokenLanguageId::new(config); // Detect language let language = extractor.compute(samples, sample_rate).unwrap(); println!("Spoken language: {}", language); // Returns language code like "en", "zh", "es", etc. } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.