Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

distil_whisper_fastrtc-0.1.0.post1.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

distil_whisper_fastrtc-0.1.0.post1-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

Details for the file distil_whisper_fastrtc-0.1.0.post1.tar.gz.

File metadata

File hashes

Hashes for distil_whisper_fastrtc-0.1.0.post1.tar.gz
Algorithm Hash digest
SHA256 03397d6404c530f6f086a9b2fc751a4d42f0c0427fa6ac78cc80dfc7113963b9
MD5 dd061f2cc116f785d10de0826faab85e
BLAKE2b-256 449effc49c654c0a8baa1eb345816c4a1b515fab09329242cc1cffd7386b2a85

See more details on using hashes here.

File details

Details for the file distil_whisper_fastrtc-0.1.0.post1-py3-none-any.whl.

File metadata

File hashes

Hashes for distil_whisper_fastrtc-0.1.0.post1-py3-none-any.whl
Algorithm Hash digest
SHA256 619f14ee4e1376ebd63477f07333050320bc2f982afeb4bcc5f071932b38cf13
MD5 ab5e3346465acf029fc42674326a7ccd
BLAKE2b-256 42a96a15945ba1cfbc2801dedbd2765aba301938324aa733e5fda0e734cb6ae3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page