Skip to main content

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/*

Metadata

Release files for whisper-cpp-client 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for whisper-cpp-client 0.1.1
File Size Uploaded
whisper_cpp_client-0.1.1.tar.gz 3.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for whisper-cpp-client 0.1.1
File Interpreter ABI Platform
whisper_cpp_client-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 8.6 kB

Release files / whisper_cpp_client-0.1.1.tar.gz

Download URL whisper_cpp_client-0.1.1.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
be4780feb4aff6d395700d758ae9661b9064c604a82b2beb9eff5a7a0421a44e
BLAKE2b-256 checksum
How to use checksums
be3aab6fb24ca53b11d0c94d7b2f8c4bbd6153c2122447059f1110d8f42ffee0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.16

Release files / whisper_cpp_client-0.1.1-py3-none-any.whl

Download URL whisper_cpp_client-0.1.1-py3-none-any.whl
Size 4.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f642a134af5fc2baf0240a85b0ba8efe39cc144ae955e93deb60f02548ac807e
BLAKE2b-256 checksum
How to use checksums
2ceaa3921e7d54cf363192a7ea8f77f4c02a78b219b0449581a944645884b77c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.16

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page