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 fastrtc.backend.fastrtc.speech_to_text import STTModel
from distil_whisper_fastrtc import DistilWhisperSTT

# Create the model
whisper_model = DistilWhisperSTT()

# 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 (Multilingual, 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.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-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: distil_whisper_fastrtc-0.1.0.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

Hashes for distil_whisper_fastrtc-0.1.0.tar.gz
Algorithm Hash digest
SHA256 722ec8e687fb53caaf556e7ce4bca87352cc135d28a414be68a3e7d46b611853
MD5 f689af07522bfbaf12a81941e06d3533
BLAKE2b-256 338647226f32bda1a79ec402ae70feab813f2bebfb5b899907114373cd6bd42e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for distil_whisper_fastrtc-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6f663617dbe56c4e8b1f3e6d837b1634ab6e065e0a2150383dfab125a152a60b
MD5 86fbafa3d20d33286a738b66d366b0b8
BLAKE2b-256 37b0f0d3c2b48e1405f510ef5776c21f3ec850894344084f73f2033d1b974d5b

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