Skip to main content

Real-time speech recognition with Whisper

Project description

Whisper-tools

High-level python library for stream and static transcription based on faster-whisper

Getting started

Installation

pip install whisper-tools

Transcribing an audio file

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)

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.

Streaming transcription locally:

from whisper_tools import WhisperLocal, StreamRecorder

recorder = StreamRecorder(WhisperLocal())

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(text)
except KeyboardInterrupt:
    print("\nStopping...")
finally:
    # stop recording
    recorder.stop_recording()

Or we can write to the file:

try:
    f = open('transcribed.txt', 'w')
    # 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:
            f.write(text + '\n')
            f.flush() 
except KeyboardInterrupt:
    print("\nStopping...")
finally:
    f.close()
    # stop recording
    recorder.stop_recording()

Streaming transcription via API:

from whisper_tools import WhisperAPI, StreamRecorderAPI

recorder = StreamRecorderAPI(WhisperAPI(api_key="your_key", base_url="your_url"))

try:
    recorder.start_recording()
    print("Recording... Press Ctrl+C to stop")
    while True:
        text = recorder.process_chunk()
        if text:
            print(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.11.tar.gz (10.0 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.11-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: whisper_tools-0.1.11.tar.gz
  • Upload date:
  • Size: 10.0 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.11.tar.gz
Algorithm Hash digest
SHA256 6a33f414a7e740ac3c9a81801086255df98b43c479d6d7df2906dca67c201019
MD5 0c839b55df6f31267364267336a4f641
BLAKE2b-256 8943464f18ac803d20900967d1caede58dbe65005174c2e5ed0614a3b9932362

See more details on using hashes here.

File details

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

File metadata

  • Download URL: whisper_tools-0.1.11-py3-none-any.whl
  • Upload date:
  • Size: 10.8 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.11-py3-none-any.whl
Algorithm Hash digest
SHA256 3700b0fc5f7b2377d124eb479eb201932291d10a202f53d4ec5163891e49df27
MD5 d82e09bbfd92f6b4064382c0a64d18b5
BLAKE2b-256 0fa14e17f2274436718c54abf6f278d6fe779d2241cf90a7b979a6d7487b1285

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