### GPU-accelerated inference Source: https://context7.com/vinairesearch/phowhisper/llms.txt This example shows how to leverage GPU acceleration for significantly faster inference by specifying the `device` parameter when initializing the pipeline. ```APIDOC ## GPU-accelerated inference ### Description To run PhoWhisper on a GPU for significantly faster inference, specify the `device` parameter when constructing the pipeline. Use `device=0` for the first CUDA GPU, or `device="cuda"` for the default GPU. ### Method `pipeline("automatic-speech-recognition", model=model_id, device=device_id)` ### Parameters #### Model Selection - **model_id** (string) - Required - The identifier for the PhoWhisper model variant to load (e.g., `"vinai/PhoWhisper-large"`). #### Device Configuration - **device** (integer or string) - Optional - Specifies the device for inference. Use `0` for the first CUDA GPU, `"cuda"` for the default GPU, or `-1` for CPU (default). ### Request Example ```python from transformers import pipeline transcriber = pipeline( "automatic-speech-recognition", model="vinai/PhoWhisper-large", device=0 # Use first CUDA GPU; set to -1 for CPU (default) ) result = transcriber("long_audio_16khz.wav") print(result['text']) ``` ### Response #### Success Response - **text** (string) - The transcribed Vietnamese text. ``` -------------------------------- ### Example Usage with Transformers Source: https://github.com/vinairesearch/phowhisper/blob/main/README.md This Python snippet demonstrates how to load and use the PhoWhisper-small model for speech recognition using the Hugging Face transformers pipeline. Ensure your audio file is sampled at 16kHz. ```python from transformers import pipeline transcriber = pipeline("automatic-speech-recognition", model="vinai/PhoWhisper-small") output = transcriber(path_to_audio_with_sampling_rate_16kHz)['text'] ``` -------------------------------- ### Batch transcription for multiple audio files Source: https://context7.com/vinairesearch/phowhisper/llms.txt This example demonstrates how to process multiple audio files efficiently by passing a list of file paths or audio dictionaries to the pipeline, enabling batched inference. ```APIDOC ## Batch transcription for multiple audio files ### Description For processing multiple audio files efficiently, pass a list of file paths or audio dicts to the pipeline. This enables batched inference and reduces overhead compared to processing files one at a time. ### Method `pipeline("automatic-speech-recognition", model=model_id)` ### Parameters #### Model Selection - **model_id** (string) - Required - The identifier for the PhoWhisper model variant to load (e.g., `"vinai/PhoWhisper-small"`). #### Input - **audio_inputs** (list) - Required - A list of file paths to audio files or dictionaries containing audio data and sampling rates. ### Request Example ```python from transformers import pipeline transcriber = pipeline( "automatic-speech-recognition", model="vinai/PhoWhisper-small" ) audio_files = [ "utterance_001.wav", "utterance_002.wav", "utterance_003.wav", ] results = transcriber(audio_files) for path, result in zip(audio_files, results): print(f"{path}: {result['text']}") # Example output: # utterance_001.wav: "xin chào" # utterance_002.wav: "cảm ơn bạn rất nhiều" # utterance_003.wav: "hẹn gặp lại" ``` ### Response #### Success Response - **results** (list of dicts) - A list where each dictionary contains the transcribed text for the corresponding audio input under the key `'text'`. ``` -------------------------------- ### Transcribe from a numpy audio array Source: https://context7.com/vinairesearch/phowhisper/llms.txt This example shows how to transcribe audio directly from a NumPy array, which is useful when integrating with audio processing libraries. The audio array and its sampling rate are passed as a dictionary. ```APIDOC ## Transcribe from a numpy audio array ### Description When integrating with audio processing libraries such as `librosa` or `soundfile`, audio can be passed directly as a numpy array alongside its sampling rate, avoiding intermediate file I/O. ### Method `pipeline("automatic-speech-recognition", model=model_id)` ### Parameters #### Model Selection - **model_id** (string) - Required - The identifier for the PhoWhisper model variant to load (e.g., `"vinai/PhoWhisper-medium"`). #### Input - **audio_input** (dict) - Required - A dictionary with keys `'array'` (numpy array of audio data) and `'sampling_rate'` (integer, expected to be 16000). ### Request Example ```python import librosa import soundfile as sf from transformers import pipeline # Load audio and resample to 16 kHz if needed audio_array, sampling_rate = librosa.load("speech.wav", sr=16000) transcriber = pipeline( "automatic-speech-recognition", model="vinai/PhoWhisper-medium" ) # Pass as a dict with 'array' and 'sampling_rate' keys result = transcriber({"array": audio_array, "sampling_rate": sampling_rate}) print(result['text']) # Example output: "tôi muốn đặt một bàn cho hai người" ``` ### Response #### Success Response - **text** (string) - The transcribed Vietnamese text. ``` -------------------------------- ### Select a model variant by size and accuracy requirement Source: https://context7.com/vinairesearch/phowhisper/llms.txt PhoWhisper offers five model sizes. This example shows how to select a specific model variant based on desired trade-offs between computational cost, memory usage, and transcription accuracy. ```APIDOC ## Select a model variant by size and accuracy requirement ### Description PhoWhisper provides five model sizes. Choose based on your latency, memory, and accuracy constraints. All share the same API surface — only the model identifier changes. The `large` variant (1.55B parameters) achieves the best WER across all benchmarks. ### Available Model Identifiers - `"vinai/PhoWhisper-tiny"` – 39M params | CMV-Vi WER: 19.05 - `"vinai/PhoWhisper-base"` – 74M params | CMV-Vi WER: 16.19 - `"vinai/PhoWhisper-small"` – 244M params | CMV-Vi WER: 11.08 - `"vinai/PhoWhisper-medium"` – 769M params | CMV-Vi WER: 8.27 - `"vinai/PhoWhisper-large"` – 1.55B params | CMV-Vi WER: 8.14 ← best accuracy ### Method `pipeline("automatic-speech-recognition", model=model_id)` ### Parameters #### Model Selection - **model_id** (string) - Required - The identifier for the PhoWhisper model variant to load (e.g., `"vinai/PhoWhisper-large"`). ### Request Example ```python from transformers import pipeline model_id = "vinai/PhoWhisper-large" transcriber = pipeline("automatic-speech-recognition", model=model_id) result = transcriber("speech_sample.wav") print(f"Transcription: {result['text']}") # Expected output: "Transcription: hôm nay thời tiết rất đẹp" ``` ### Response #### Success Response - **text** (string) - The transcribed Vietnamese text. ``` -------------------------------- ### Transcribe audio using the Hugging Face `pipeline` API Source: https://context7.com/vinairesearch/phowhisper/llms.txt This snippet demonstrates the basic usage of PhoWhisper by loading a model and transcribing a local audio file. The pipeline handles all necessary steps for speech recognition. ```APIDOC ## Transcribe audio using the Hugging Face `pipeline` API ### Description This is the simplest way to use PhoWhisper via the `transformers.pipeline` interface, which handles model loading, feature extraction, and decoding automatically. Pass a path to a 16 kHz WAV file (or a numpy array / dict with `array` and `sampling_rate` keys) and retrieve the transcribed Vietnamese text from the `'text'` key of the returned dict. ### Method `pipeline("automatic-speech-recognition", model="vinai/PhoWhisper-small")` ### Parameters #### Model Selection - **model** (string) - Required - The identifier for the PhoWhisper model to load (e.g., `"vinai/PhoWhisper-small"`). #### Input - **audio_input** (string or dict or numpy array) - Required - Path to a 16 kHz WAV file, or a dictionary containing an audio array and its sampling rate, or a numpy array representing the audio. ### Request Example ```python from transformers import pipeline # Load PhoWhisper-small (244M parameters, good speed/accuracy balance) transcriber = pipeline( "automatic-speech-recognition", model="vinai/PhoWhisper-small" ) # Transcribe a local audio file (must be 16 kHz sampling rate) path_to_audio = "audio_16khz.wav" result = transcriber(path_to_audio) print(result['text']) # Example output: "xin chào tôi là trợ lý ảo của bạn" ``` ### Response #### Success Response - **text** (string) - The transcribed Vietnamese text. ``` -------------------------------- ### Transcribe from Numpy Audio Array Source: https://context7.com/vinairesearch/phowhisper/llms.txt Integrate PhoWhisper with audio processing libraries by passing audio directly as a numpy array and its sampling rate. This avoids intermediate file I/O and requires audio to be sampled at 16 kHz. ```python import librosa import soundfile as sf from transformers import pipeline # Load audio and resample to 16 kHz if needed audio_array, sampling_rate = librosa.load("speech.wav", sr=16000) transcriber = pipeline( "automatic-speech-recognition", model="vinai/PhoWhisper-medium" ) # Pass as a dict with 'array' and 'sampling_rate' keys result = transcriber({"array": audio_array, "sampling_rate": sampling_rate}) print(result['text']) # Example output: "tôi muốn đặt một bàn cho hai người" ``` -------------------------------- ### Transcribe Audio File with PhoWhisper Source: https://context7.com/vinairesearch/phowhisper/llms.txt Use the `transformers.pipeline` API to load a PhoWhisper model and transcribe a local 16 kHz WAV audio file. The result is returned in a dictionary with a 'text' key. ```python from transformers import pipeline # Load PhoWhisper-small (244M parameters, good speed/accuracy balance) transcriber = pipeline( "automatic-speech-recognition", model="vinai/PhoWhisper-small" ) # Transcribe a local audio file (must be 16 kHz sampling rate) path_to_audio = "audio_16khz.wav" result = transcriber(path_to_audio) print(result['text']) # Example output: "xin chào tôi là trợ lý ảo của bạn" ``` -------------------------------- ### GPU-Accelerated Inference with PhoWhisper Source: https://context7.com/vinairesearch/phowhisper/llms.txt Run PhoWhisper inference on a GPU for faster processing by specifying the `device` parameter when creating the pipeline. Use `device=0` for the first CUDA GPU or `device="cuda"` for the default. ```python from transformers import pipeline transcriber = pipeline( "automatic-speech-recognition", model="vinai/PhoWhisper-large", device=0 # Use first CUDA GPU; set to -1 for CPU (default) ) result = transcriber("long_audio_16khz.wav") print(result['text']) ``` -------------------------------- ### Batch Transcription for Multiple Audio Files Source: https://context7.com/vinairesearch/phowhisper/llms.txt Process multiple audio files efficiently by passing a list of file paths or audio dictionaries to the pipeline. This enables batched inference and reduces processing overhead. ```python from transformers import pipeline transcriber = pipeline( "automatic-speech-recognition", model="vinai/PhoWhisper-small" ) audio_files = [ "utterance_001.wav", "utterance_002.wav", "utterance_003.wav", ] results = transcriber(audio_files) for path, result in zip(audio_files, results): print(f"{path}: {result['text']}") # Example output: # utterance_001.wav: "xin chào" # utterance_002.wav: "cảm ơn bạn rất nhiều" # utterance_003.wav: "hẹn gặp lại" ``` -------------------------------- ### Select PhoWhisper Model Variant Source: https://context7.com/vinairesearch/phowhisper/llms.txt Choose a PhoWhisper model size based on accuracy and computational requirements. The API remains the same; only the model identifier changes. Available models range from `tiny` to `large`. ```python from transformers import pipeline # Available model identifiers: # "vinai/PhoWhisper-tiny" – 39M params | CMV-Vi WER: 19.05 # "vinai/PhoWhisper-base" – 74M params | CMV-Vi WER: 16.19 # "vinai/PhoWhisper-small" – 244M params | CMV-Vi WER: 11.08 # "vinai/PhoWhisper-medium" – 769M params | CMV-Vi WER: 8.27 # "vinai/PhoWhisper-large" – 1.55B params | CMV-Vi WER: 8.14 ← best accuracy model_id = "vinai/PhoWhisper-large" transcriber = pipeline("automatic-speech-recognition", model=model_id) result = transcriber("speech_sample.wav") print(f"Transcription: {result['text']}") # Expected output: "Transcription: hôm nay thời tiết rất đẹp" ``` -------------------------------- ### Cite PhoWhisper Paper Source: https://github.com/vinairesearch/phowhisper/blob/main/README.md Use this BibTeX entry when citing the PhoWhisper paper in academic or published works. ```bibtex @inproceedings{PhoWhisper, title = {{PhoWhisper: Automatic Speech Recognition for Vietnamese}}, author = {Thanh-Thien Le and Linh The Nguyen and Dat Quoc Nguyen}, booktitle = {Proceedings of the ICLR 2024 Tiny Papers track}, year = {2024} } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.