Skip to main content

Real-time speech recognition with Whisper

Project description

Whisper-tools

High-level python library for stream and static transcription with whisper

Getting started

Installation

pip install whisper-tools

Usage

  • For transcription using a local Whisper model (downloaded automatically), create a transcriber - an object of the WhisperLocal class:
from whisper_tools import WhisperLocal

transcriber = WhisperLocal()

# WhisperLocal(model_name="openai/whisper-tiny", language='en', device='auto'))
  • For transcription using an LLM via API, create a transcriber - an object of the WhisperAPI class:
from whisper_tools import WhisperAPI

transcriber_api = WhisperAPI(api_key="your_key", base_url="your_url")

# WhisperAPI(api_key="your_key", base_url="your_url", model="your_model")

Transcribing an audio file

  • For local transcription: text = transcriber.transcribe_file('path-to-file.wav')
  • For transcription using an LLM via API: text = transcriber.transcribe_file_api('path-to-file.wav')

Real-time transcription

[!IMPORTANT]
True streaming transcription requires modifications to the Whisper architecture, as the original model expects a complete audio file, so we send information in chunks.

  • For local transcription: create an object of the StreamRecorder class and pass it our transcriber recorder = StreamRecorder(WhisperLocal())
  • For transcription using an LLM via API: create an object of the StreamRecorderAPI class and pass it our transcriber recorder = StreamRecorder(WhisperAPI(api_key="your_key", base_url="your_url"))
try:
    # start recording
    recorder.start_recording()
    print("Recording... Press Ctrl+C to stop")
    while True:
        # get a chunk (block of transcribed speech)
        text = recorder.process_chunk()
        if text:
            print(f"Recognized: {text}")
except KeyboardInterrupt:
    print("\nStopping...")
finally:
    # stop recording
    recorder.stop_recording()

Examples

Transcribing an audio file locally:

from whisper_tools import WhisperLocal

text = WhisperLocal().transcribe_file("/voice example/example.wav")

print(text)

Transcribing an audio file via API::

from whisper_tools import WhisperAPI

whisper_api = WhisperAPI(api_key="your_key", base_url="your_url")
text = whisper_api.transcribe_file_api("/voice example/example.wav")

print(text)

Streaming transcription locally:

from whisper_tools import WhisperLocal, StreamRecorder

recorder = StreamRecorder(WhisperLocal())
# StreamRecorder(WhisperLocal(), sample_rate=16000, chunk_duration=5, min_interval=2.0)

try:
    recorder.start_recording()
    print("Recording... Press Ctrl+C to stop")
    while True:
        text = recorder.process_chunk()
        if text:
            print(f"Recognized: {text}")
except KeyboardInterrupt:
    print("\nStopping...")
finally:
    recorder.stop_recording()

Streaming transcription via API:

from whisper_tools import WhisperAPI, StreamRecorderAPI

recorder = StreamRecorderAPI(WhisperAPI(api_key="your_key", base_url="your_url"))
# StreamRecorderAPI(WhisperAPI(), sample_rate=16000, chunk_duration=5, min_interval=2.0)

try:
    recorder.start_recording()
    print("Recording... Press Ctrl+C to stop")
    while True:
        text = recorder.process_chunk()
        if text:
            print(f"Recognized: {text}")
except KeyboardInterrupt:
    print("\nStopping...")
finally:
    recorder.stop_recording()

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

whisper_tools-0.1.2.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

whisper_tools-0.1.2-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file whisper_tools-0.1.2.tar.gz.

File metadata

  • Download URL: whisper_tools-0.1.2.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for whisper_tools-0.1.2.tar.gz
Algorithm Hash digest
SHA256 6f489180caef8cc2291e8243aabf27c92a6a33d2aed21c4919ae1a64958a4848
MD5 909f316dc47c8e4c3693fec4615fc923
BLAKE2b-256 8ebba8e343170219f2be01a27369d1e0eab01967406a48c35060ae024d16c97b

See more details on using hashes here.

File details

Details for the file whisper_tools-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: whisper_tools-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.0

File hashes

Hashes for whisper_tools-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b8bba46eb14d8bdf9443de4708b59fa458434cbc4552266e7a19a57ef7ec0c60
MD5 a5137aa37a26ee88b9aca8a4ff4b52d8
BLAKE2b-256 a1f843a0c26ea4187fd2fb17d2ae20dcad708be1b2cbc455d8e04da98fd40f78

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