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
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file whisper_tools-0.1.3.tar.gz.
File metadata
- Download URL: whisper_tools-0.1.3.tar.gz
- Upload date:
- Size: 7.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6b4082b014cde0200cbc2f74a910561992b07ba41eda9107cb7a4771f8b07bcc
|
|
| MD5 |
33dbc82b22f558039180ddbb73833c15
|
|
| BLAKE2b-256 |
1b29dfb2dacd328088b70c169831dc4f8b6a1d9804536f1dc7bf225f7de00af8
|
File details
Details for the file whisper_tools-0.1.3-py3-none-any.whl.
File metadata
- Download URL: whisper_tools-0.1.3-py3-none-any.whl
- Upload date:
- Size: 8.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f63d1ffe832801d18248e7fb0af4fc9a2222abffbcf3de1a720780a9d4d9c7cc
|
|
| MD5 |
798b583b3dfe07529fe12463e6236122
|
|
| BLAKE2b-256 |
02f8e4dd51a60ced0f37c695a0ba3ec61b968f9f236d0721e3cd0eeeb83a47fb
|