A small, lightweight client for the whisper.cpp server.
Project description
Whisper CPP Client in Python
A small, lightweight python client for the Whisper.cpp server.
Prerequisites
You need to have the Whisper.cpp server running in your network. You can find the server code in the Whisper.cpp repository.
Installation
To install the Whisper CPP client, you can use pip:
pip install whisper-cpp-client
Usage
To use the Whisper CPP client, you can import the WhisperClient class from the whisper_cpp_client module:
from whisper_cpp_client import WhisperClient
import json
client = WhisperClient("localhost", 3333)
try:
response_content = client.transcribe("path/to/audio/file.wav")
# How you handle the response_content, depends on the response_format
# parameter which defaults to 'json'.
data = json.loads(response_content)
print(data)
except Exception as e:
print('Handle errors...')
The client basically only has two methods: transcribe and set_params. The transcribe method takes an audio file path (only 16-bit WAV files are supported by whisper.cpp) and returns the transcription result, while the set_params expects a dictionary of parameters that will be passed to the Whisper.cpp server.
These are the available parameters with the default values based on the Whisper.cpp server configuration (consult the whisper.cpp documentation for more details):
params = {
'response_format': 'json', # json, text, srt, verbose_json, vtt
'temperature': 0.0,
'temperature_inc': 0.2,
'offset_t': 0,
'offset_n': 0,
'duration': 0,
'progress_step': 5,
'max_context': -1,
'max_len': 0,
'best_of': 2,
'beam_size': -1,
'audio_ctx': 0,
'word_thold': 0.01,
'entropy_thold': 2.4,
'logprob_thold': -1.0,
'no_speech_thold': 0.6,
'debug_mode': False,
'translate': False,
'detect_language': False,
'diarize': False,
'tinydiarize': False,
'split_on_word': False,
'no_fallback': False,
'print_special': False,
'print_colors': False,
'print_realtime': False,
'print_progress': False,
'no_timestamps': False,
'use_gpu': True,
'flash_attn': False,
'suppress_nst':False
}
client = WhisperClient("localhost", 3333)
client.set_params(params)
Development
Create a venv install dependencies and run the example:
python -m venv .
source venv/bin/activate
pip install -r requirements.txt
python examples/test.py
Distribution
To build and upload to pypi, first update version in __init__.py and the pyproject.toml then run run:
rm -r dist
python -m build
python -m twine upload --repository testpypi dist/*
python -m twine upload dist/*
Project details
Release history Release notifications | RSS feed
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_cpp_client-0.1.1.tar.gz.
File metadata
- Download URL: whisper_cpp_client-0.1.1.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
be4780feb4aff6d395700d758ae9661b9064c604a82b2beb9eff5a7a0421a44e
|
|
| MD5 |
98396bb7e7f553b4c5d4db2c506b323a
|
|
| BLAKE2b-256 |
be3aab6fb24ca53b11d0c94d7b2f8c4bbd6153c2122447059f1110d8f42ffee0
|
File details
Details for the file whisper_cpp_client-0.1.1-py3-none-any.whl.
File metadata
- Download URL: whisper_cpp_client-0.1.1-py3-none-any.whl
- Upload date:
- Size: 4.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f642a134af5fc2baf0240a85b0ba8efe39cc144ae955e93deb60f02548ac807e
|
|
| MD5 |
824b4c4e5c3fd03ce416e30d9456fbcd
|
|
| BLAKE2b-256 |
2ceaa3921e7d54cf363192a7ea8f77f4c02a78b219b0449581a944645884b77c
|