### Real-time ASR Inference with NeMo FastConformer (Python) Source: https://context7.com/scb-10x/typhoon-isan/llms.txt Performs real-time speech recognition on Isan audio files using a pre-trained NeMo FastConformer model. It loads the model, transcribes a given audio file, and prints the resulting text. Ensure the 'scb10x/typhoon-isan-asr-realtime' model is accessible and PyTorch is installed. ```python #!/usr/bin/env python3 import nemo.collections.asr as nemo_asr import torch # Load the Typhoon Isan ASR Real-Time model device = 'cuda' if torch.cuda.is_available() else 'cpu' model = nemo_asr.models.ASRModel.from_pretrained( model_name="scb10x/typhoon-isan-asr-realtime", map_location=device ) # Run basic transcription audio_file = "isan_speech.wav" transcriptions = model.transcribe(audio=[audio_file]) transcription_text = transcriptions[0] print(f"Transcription: {transcription_text}") # Output: Transcription: สวัสดีจ้ออีหลี... ``` -------------------------------- ### Complete FastConformer Inference Pipeline (Python) Source: https://context7.com/scb-10x/typhoon-isan/llms.txt An end-to-end Python script demonstrating the complete ASR pipeline using the FastConformer model. It covers model loading, audio preprocessing (resampling and normalization), transcription, and performance calculation (RTF). Dependencies include NeMo, PyTorch, librosa, and soundfile. ```python #!/usr/bin/env python3 import nemo.collections.asr as nemo_asr import torch import librosa import soundfile as sf import time from pathlib import Path # 1. Load model device = 'cuda' if torch.cuda.is_available() else 'cpu' print(f"Loading model on {device}...") model = nemo_asr.models.ASRModel.from_pretrained( model_name="scb10x/typhoon-isan-asr-realtime", map_location=device ) # 2. Prepare audio input_file = "raw_isan_recording.m4a" output_file = "processed_audio.wav" # Load and resample y, sr = librosa.load(input_file, sr=None) duration = len(y) / sr if sr != 16000: y = librosa.resample(y, orig_sr=sr, target_sr=16000) # Normalize y = y / (max(abs(y)) + 1e-8) # Save sf.write(output_file, y, 16000) print(f"Audio prepared: {duration:.1f}s at 16kHz") # 3. Run transcription start_time = time.time() transcriptions = model.transcribe(audio=[output_file]) processing_time = time.time() - start_time transcription = transcriptions[0] if transcriptions else "" # 4. Calculate performance rtf = processing_time / duration if duration > 0 else 0 ``` -------------------------------- ### Whisper Command-Line Inference Source: https://context7.com/scb-10x/typhoon-isan/llms.txt Run Typhoon Whisper ASR from the command line. Allows specifying custom models, forcing CPU processing, and explicitly setting the language for transcription. Requires Python and the Whisper implementation. ```bash # Basic usage with default model python inference/inference_whisper.py isan_audio.mp3 # Output: # 🌪️ Loading Whisper model: scb10x/typhoon-isan-asr-whisper # Device: cuda:0 | Precision: torch.float16 # 🎙️ Transcribing isan_audio.mp3... # ================================================== # 📝 Results (Processing Time: 3.21s) # ================================================== # Full Text: # สวัสดีจ้าว เจ้ามาจากใสบ่าว บ่าวมาจากอีสาน... # Specify custom model python inference/inference_whisper.py audio.wav --model scb10x/custom-isan-model # Force CPU processing python inference/inference_whisper.py audio.m4a --device cpu # Specify language explicitly python inference/inference_whisper.py audio.flac --language th --device cuda ``` -------------------------------- ### FastConformer Command-Line Inference Source: https://context7.com/scb-10x/typhoon-isan/llms.txt Execute Isan ASR inference using the FastConformer model directly from the command line. Supports basic transcription, timestamp estimation, and device selection (CPU/GPU). ```bash # Basic transcription python inference/inference_fastconformer.py isan_audio.m4a # Output: # 🌪️ Typhoon Isan ASR Real-Time Inference # ================================================== # 🌪️ Loading Typhoon Isan ASR Real-Time model... # Device: CUDA # 🎵 Processing audio: isan_audio.m4a # Original: 44100 Hz, 45.3s # Resampled: 44100 Hz → 16000 Hz # ✅ Processed: processed_isan_audio.wav # 🎙️ Running basic transcription... # ================================================== # 📝 TRANSCRIPTION RESULTS # ================================================== # Mode: basic # File: isan_audio.m4a # Duration: 45.3s # Processing: 2.45s # RTF: 0.054x 🚀 (Real-time capable!) # Transcription: 'สวัสดีจ้ออีหลี บ่าวมาจากใส...' # ✅ Processing complete! # With timestamp estimation python inference/inference_fastconformer.py isan_audio.wav --with-timestamps # With GPU acceleration python inference/inference_fastconformer.py isan_audio.mp3 --device cuda # Force CPU processing python inference/inference_fastconformer.py isan_audio.flac --device cpu ``` -------------------------------- ### Audio Preprocessing for Isan ASR (Python) Source: https://context7.com/scb-10x/typhoon-isan/llms.txt Prepares audio files for ASR processing by resampling to 16kHz and normalizing volume. This function supports various audio formats and saves the processed audio as a WAV file. It requires 'librosa' and 'soundfile' libraries. The function returns a success status, the path to the processed file, and relevant metadata. ```python import librosa import soundfile as sf from pathlib import Path def prepare_audio(input_path, output_path=None, target_sr=16000): """ Prepare audio file for Typhoon ASR Isan Real-Time processing Supports: .wav, .mp3, .m4a, .flac, .ogg, .aac, .webm """ input_path = Path(input_path) if not input_path.exists(): return False, None, {"error": f"File not found: {input_path}"} if output_path is None: output_path = f"processed_{input_path.stem}.wav" # Load and resample audio y, sr = librosa.load(str(input_path), sr=None) if y is None: return False, None, {"error": "Failed to load audio"} duration = len(y) / sr if sr != target_sr: y = librosa.resample(y, orig_sr=sr, target_sr=target_sr) # Normalize audio y = y / (max(abs(y)) + 1e-8) # Save processed audio sf.write(output_path, y, target_sr) return True, output_path, { "original_sr": sr, "target_sr": target_sr, "duration": duration, "output_path": output_path } # Usage example success, processed_file, info = prepare_audio( "raw_isan_audio.m4a", target_sr=16000 ) if success: print(f"Audio processed: {processed_file}") print(f"Duration: {info['duration']:.1f}s") # Output: Audio processed: processed_raw_isan_audio.wav # Duration: 45.3s ``` -------------------------------- ### Audio Preprocessing for ASR Source: https://context7.com/scb-10x/typhoon-isan/llms.txt Prepare audio files in various formats for Isan ASR processing by resampling to 16kHz and normalizing. Supports multiple audio file types. ```APIDOC ## Audio Preprocessing for ASR ### Description This function prepares audio files for the Typhoon Isan ASR Real-Time model. It resamples the audio to 16kHz and normalizes the amplitude. It supports various common audio formats. ### Method POST (implicitly via Python SDK) ### Endpoint N/A (Python SDK interaction) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (function takes file paths as arguments) ### Function Signature `prepare_audio(input_path, output_path=None, target_sr=16000)` ### Parameters - **input_path** (string) - Required - Path to the input audio file. - **output_path** (string) - Optional - Path to save the processed audio file. Defaults to `processed_{input_path.stem}.wav`. - **target_sr** (integer) - Optional - The target sampling rate. Defaults to 16000. ### Request Example ```python import librosa import soundfile as sf from pathlib import Path def prepare_audio(input_path, output_path=None, target_sr=16000): """ Prepare audio file for Typhoon ASR Isan Real-Time processing Supports: .wav, .mp3, .m4a, .flac, .ogg, .aac, .webm """ input_path = Path(input_path) if not input_path.exists(): return False, None, {"error": f"File not found: {input_path}"} if output_path is None: output_path = f"processed_{input_path.stem}.wav" # Load and resample audio y, sr = librosa.load(str(input_path), sr=None) if y is None: return False, None, {"error": "Failed to load audio"} duration = len(y) / sr if sr != target_sr: y = librosa.resample(y, orig_sr=sr, target_sr=target_sr) # Normalize audio y = y / (max(abs(y)) + 1e-8) # Save processed audio sf.write(output_path, y, target_sr) return True, output_path, { "original_sr": sr, "target_sr": target_sr, "duration": duration, "output_path": output_path } # Usage example success, processed_file, info = prepare_audio( "raw_isan_audio.m4a", target_sr=16000 ) if success: print(f"Audio processed: {processed_file}") print(f"Duration: {info['duration']:.1f}s") ``` ### Response #### Success Response (200) - **success** (boolean) - Indicates if the audio processing was successful. - **processed_file** (string) - The path to the processed audio file if successful. - **info** (object) - Contains metadata about the processed audio. - **original_sr** (integer) - The original sampling rate of the audio. - **target_sr** (integer) - The target sampling rate (e.g., 16000). - **duration** (float) - The duration of the audio in seconds. - **output_path** (string) - The path where the processed audio was saved. #### Response Example ```json { "success": true, "processed_file": "processed_raw_isan_audio.wav", "info": { "original_sr": 44100, "target_sr": 16000, "duration": 45.3, "output_path": "processed_raw_isan_audio.wav" } } ``` ``` -------------------------------- ### ASR with Word Timestamp Estimation (Python) Source: https://context7.com/scb-10x/typhoon-isan/llms.txt Generates transcriptions with estimated word-level timestamps for Isan speech. This script uses the NeMo ASR model to transcribe audio, calculates the duration of each word based on audio length and word count, and then outputs the transcription, processing time, real-time factor, and word timestamps. It requires 'nemo', 'soundfile', and 'time' modules. ```python import nemo.collections.asr as nemo_asr import soundfile as sf import time # Load model model = nemo_asr.models.ASRModel.from_pretrained( model_name="scb10x/typhoon-isan-asr-realtime" ) audio_file = "isan_speech.wav" # Get audio duration audio_info = sf.info(audio_file) audio_duration = audio_info.duration # Perform transcription with hypotheses start_time = time.time() result = model.transcribe(audio=[audio_file], return_hypotheses=True) transcription = "" if result and len(result) > 0: hypothesis = result[0] if hasattr(hypothesis, 'text'): transcription = hypothesis.text processing_time = time.time() - start_time # Generate estimated timestamps timestamps = [] if transcription and audio_duration > 0: words = transcription.split() avg_duration = audio_duration / len(words) for i, word in enumerate(words): start_t = i * avg_duration end_t = start_t + avg_duration timestamps.append({ 'word': word, 'start': start_t, 'end': end_t }) # Display results rtf = processing_time / audio_duration print(f"Transcription: {transcription}") print(f"Processing time: {processing_time:.2f}s") print(f"Real-time factor: {rtf:.3f}x") print("\nWord Timestamps:") for ts in timestamps[:5]: print(f" [{ts['start']:6.2f}s - {ts['end']:6.2f}s] {ts['word']}") # Output: Transcription: สวัสดี จ้าว เจ้า บ่าว มา จาก ใส # Processing time: 2.45s # Real-time factor: 0.054x # Word Timestamps: ``` -------------------------------- ### Whisper-based ASR Pipeline (Python) Source: https://context7.com/scb-10x/typhoon-isan/llms.txt Perform ASR using the Typhoon Whisper model via Hugging Face Transformers in Python. This pipeline includes automatic chunking for handling long audio files efficiently. It requires PyTorch and the Transformers library. ```python import torch from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor, pipeline # Load model and create pipeline device = "cuda:0" if torch.cuda.is_available() else "cpu" torch_dtype = torch.float16 if torch.cuda.is_available() else torch.float32 model_id = "scb10x/typhoon-isan-asr-whisper" model = AutoModelForSpeechSeq2Seq.from_pretrained( model_id, torch_dtype=torch_dtype, low_cpu_mem_usage=True, use_safetensors=True ) model.to(device) processor = AutoProcessor.from_pretrained(model_id) # Create ASR pipeline with automatic chunking pipe = pipeline( "automatic-speech-recognition", model=model, tokenizer=processor.tokenizer, feature_extractor=processor.feature_extractor, max_new_tokens=128, chunk_length_s=30, # Process in 30-second chunks for long audio batch_size=16, return_timestamps=True, torch_dtype=torch_dtype, device=device, ) # Run inference audio_file = "long_isan_speech.mp3" result = pipe( audio_file, generate_kwargs={"language": "th", "task": "transcribe"} ) print(f"Transcription: {result['text']}") # Output: Transcription: สวัสดีจ้าว เจ้ามาจากใสบ่าว บ่าวมาจากอีสาน... ``` -------------------------------- ### Display ASR Results and Cleanup Source: https://context7.com/scb-10x/typhoon-isan/llms.txt This Python code snippet demonstrates how to print the ASR processing results such as transcription, audio duration, processing time, and real-time factor. It also includes logic to clean up the output file if it exists. ```python print(f"\nTranscription: {transcription}") print(f"Audio duration: {duration:.1f}s") print(f"Processing time: {processing_time:.2f}s") print(f"Real-time factor: {rtf:.3f}x") if rtf < 1.0: print("✅ Real-time capable!") else: print("✅ Suitable for batch processing") # Cleanup import os if os.path.exists(output_file): os.remove(output_file) ``` -------------------------------- ### ASR with Timestamp Estimation Source: https://context7.com/scb-10x/typhoon-isan/llms.txt Generate transcriptions with estimated word-level timestamps for Isan speech using the Typhoon Isan ASR model. ```APIDOC ## ASR with Timestamp Estimation ### Description This functionality allows you to obtain transcriptions of Isan speech along with estimated start and end times for each word. It leverages the Typhoon Isan ASR model and calculates timestamps based on audio duration and the number of transcribed words. ### Method POST (implicitly via Python SDK) ### Endpoint N/A (Python SDK interaction) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (function takes audio file path as input) ### Request Example ```python import nemo.collections.asr as nemo_asr import soundfile as sf import time # Load model model = nemo_asr.models.ASRModel.from_pretrained( model_name="scb10x/typhoon-isan-asr-realtime" ) audio_file = "isan_speech.wav" # Get audio duration audio_info = sf.info(audio_file) audio_duration = audio_info.duration # Perform transcription with hypotheses start_time = time.time() result = model.transcribe(audio=[audio_file], return_hypotheses=True) transcription = "" if result and len(result) > 0: hypothesis = result[0] if hasattr(hypothesis, 'text'): transcription = hypothesis.text processing_time = time.time() - start_time # Generate estimated timestamps timestamps = [] if transcription and audio_duration > 0: words = transcription.split() avg_duration = audio_duration / len(words) for i, word in enumerate(words): start_t = i * avg_duration end_t = start_t + avg_duration timestamps.append({ 'word': word, 'start': start_t, 'end': end_t }) # Display results rtf = processing_time / audio_duration print(f"Transcription: {transcription}") print(f"Processing time: {processing_time:.2f}s") print(f"Real-time factor: {rtf:.3f}x") print("\nWord Timestamps:") for ts in timestamps[:5]: print(f" [{ts['start']:6.2f}s - {ts['end']:6.2f}s] {ts['word']}") ``` ### Response #### Success Response (200) - **transcription** (string) - The full transcribed text. - **processing_time** (float) - The time taken for ASR processing in seconds. - **real_time_factor** (float) - The ratio of processing time to audio duration. - **timestamps** (array of objects) - A list of objects, each representing a word with its estimated start and end times. - **word** (string) - The transcribed word. - **start** (float) - The estimated start time of the word in seconds. - **end** (float) - The estimated end time of the word in seconds. #### Response Example ```json { "transcription": "สวัสดี จ้าว เจ้า บ่าว มา จาก ใส", "processing_time": 2.45, "real_time_factor": 0.054, "timestamps": [ {"word": "สวัสดี", "start": 0.00, "end": 0.50}, {"word": "จ้าว", "start": 0.50, "end": 1.00}, {"word": "เจ้า", "start": 1.00, "end": 1.50}, {"word": "บ่าว", "start": 1.50, "end": 2.00}, {"word": "มา", "start": 2.00, "end": 2.50} ] } ``` ``` -------------------------------- ### FastConformer ASR Inference Source: https://context7.com/scb-10x/typhoon-isan/llms.txt Perform real-time speech recognition for Isan audio files using the Typhoon Isan ASR Real-Time model based on the NeMo FastConformer architecture. ```APIDOC ## FastConformer ASR Inference ### Description This endpoint provides real-time speech recognition capabilities for the Isan language using a pre-trained FastConformer model. ### Method POST (implicitly via Python SDK) ### Endpoint N/A (Python SDK interaction) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None (model is loaded and then transcription is performed on audio files) ### Request Example ```python import nemo.collections.asr as nemo_asr import torch # Load the Typhoon Isan ASR Real-Time model device = 'cuda' if torch.cuda.is_available() else 'cpu' model = nemo_asr.models.ASRModel.from_pretrained( model_name="scb10x/typhoon-isan-asr-realtime", map_location=device ) # Run basic transcription audio_file = "isan_speech.wav" transcriptions = model.transcribe(audio=[audio_file]) transcription_text = transcriptions[0] print(f"Transcription: {transcription_text}") ``` ### Response #### Success Response (200) - **transcription_text** (string) - The transcribed text from the audio file. #### Response Example ```json { "transcription_text": "สวัสดีจ้ออีหลี..." } ``` ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.