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.12.tar.gz (10.3 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.12-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: whisper_tools-0.1.12.tar.gz
  • Upload date:
  • Size: 10.3 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.12.tar.gz
Algorithm Hash digest
SHA256 d7f27d42e723d94f60e58faf51c33b0803b053f9e714f80aedb7b3e002a24a42
MD5 fe3aa9d9ee889a59c4bfbdf4986970e7
BLAKE2b-256 fd3bd136f4a8a7181fa41e6b83acea0c9d54aff4d847133fa005c4ee8c44b619

See more details on using hashes here.

File details

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

File metadata

  • Download URL: whisper_tools-0.1.12-py3-none-any.whl
  • Upload date:
  • Size: 11.7 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.12-py3-none-any.whl
Algorithm Hash digest
SHA256 5c4a2363cab2231ca7fbe85f8256b2939da7a14dd80e66574149c2c5c9ff8f02
MD5 2d6cf4c262c76b066d9d8649bbcee267
BLAKE2b-256 cdff782c1bf106e6d2b998d7c18580e893e45bfdeb0b49a0f8dfeb7f524c311e

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