Distil-Whisper wrapper for FastRTC speech-to-text
Project description
Distil-Whisper for FastRTC
A PyPI package that wraps Hugging Face's Distil-Whisper model for speech-to-text (STT) transcription, compatible with the FastRTC STTModel protocol.
Installation
pip install distil-whisper-fastrtc
For audio file loading capabilities, install with the audio extras:
pip install distil-whisper-fastrtc[audio]
For development:
pip install distil-whisper-fastrtc[dev]
Usage
Basic Usage
from distil_whisper_fastrtc import get_stt_model
import numpy as np
# Create the model (downloads from HF if not cached)
model = get_stt_model()
# Example: Create a sample audio array (actual audio would come from a file or mic)
sample_rate = 16000
audio_data = np.zeros(16000, dtype=np.float32) # 1 second of silence
# Transcribe
text = model.stt((sample_rate, audio_data))
print(f"Transcription: {text}")
Loading Audio Files
If you've installed with the audio extras:
from distil_whisper_fastrtc import get_stt_model, load_audio
# Load model
model = get_stt_model()
# Load audio file (automatically resamples to 16kHz)
audio = load_audio("path/to/audio.wav")
# Transcribe
text = model.stt(audio)
print(f"Transcription: {text}")
Using with FastRTC
from distil_whisper_fastrtc import get_stt_model
# Create the model
whisper_model = get_stt_model()
# Use within FastRTC applications
# (Follow FastRTC documentation for integration details)
Available Models
You can choose from different model sizes:
distil-whisper/distil-small.en(default, English only, fastest)distil-whisper/distil-medium.en(English only, better quality)distil-whisper/distil-large-v2(English highest quality)distil-whisper/distil-large-v3(Latest version, best quality)
Example:
from distil_whisper_fastrtc import get_stt_model
# Choose a larger model
model = get_stt_model("distil-whisper/distil-large-v2")
Advanced Configuration
You can configure the model with various parameters:
from distil_whisper_fastrtc import DistilWhisperSTT
# Configure with specific device and precision
model = DistilWhisperSTT(
model="distil-whisper/distil-medium.en",
device="cuda", # Use GPU if available
dtype="float16" # Use half precision for faster inference
)
Requirements
- Python 3.8+
- PyTorch 1.10+
- transformers 4.30+
- numpy 1.20+
- accelerate 0.20+ (for faster inference)
- librosa 0.9+ (optional, for audio file loading)
Development
Clone the repository and install in development mode:
git clone https://github.com/yourusername/distil-whisper-fastrtc.git
cd distil-whisper-fastrtc
pip install -e ".[dev,audio]"
Run tests:
pytest tests/
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file distil_whisper_fastrtc-0.1.0.post1.tar.gz.
File metadata
- Download URL: distil_whisper_fastrtc-0.1.0.post1.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
03397d6404c530f6f086a9b2fc751a4d42f0c0427fa6ac78cc80dfc7113963b9
|
|
| MD5 |
dd061f2cc116f785d10de0826faab85e
|
|
| BLAKE2b-256 |
449effc49c654c0a8baa1eb345816c4a1b515fab09329242cc1cffd7386b2a85
|
File details
Details for the file distil_whisper_fastrtc-0.1.0.post1-py3-none-any.whl.
File metadata
- Download URL: distil_whisper_fastrtc-0.1.0.post1-py3-none-any.whl
- Upload date:
- Size: 6.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
619f14ee4e1376ebd63477f07333050320bc2f982afeb4bcc5f071932b38cf13
|
|
| MD5 |
ab5e3346465acf029fc42674326a7ccd
|
|
| BLAKE2b-256 |
42a96a15945ba1cfbc2801dedbd2765aba301938324aa733e5fda0e734cb6ae3
|