Skip to main content

A Python wrapper for whisper.cpp

Project description

whisper-cpp-python

GitHub Workflow Status (with branch) GitHub PyPI

whisper-cpp-python is a Python module inspired by llama-cpp-python that provides a Python interface to the whisper.cpp model. This module automatically parses the C++ header file of the project during building time, generating the corresponding Python bindings.

Installation

To install the module, you can use pip:

pip install whisper-cpp-python

Usage

To use the module, you need to create an instance of the Whisper class, passing the path to the model file as a parameter. Then, you can call the transcribe method to transcribe a given audio file.

from whisper_cpp_python import Whisper

model = Whisper('vendor/whisper.cpp/models/ggml-tiny.bin')
print(model.transcribe('vendor/whisper.cpp/samples/jfk.wav'))

In the example above, the module transcribes the jfk.wav audio file using the ggml-tiny model.

All interfaces provided by whisper.h are available in python. The following example show how to pass a custom progress_callback function to the model.

from whisper_cpp_python import Whisper
from whisper_cpp_python.whisper_cpp import whisper_progress_callback

def callback(ctx, state, i, p):
    print(i)

model = Whisper('../quantized_models/whisper/models/ggml-tiny.bin')
model.params.progress_callback = whisper_progress_callback(callback)

print(model.transcribe('vendor/whisper.cpp/samples/jfk.wav'))

License

whisper-cpp-python is released under the MIT License. See LICENSE for details.

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_cpp_python-0.1.10.tar.gz (3.8 MB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page