Skip to main content

No project description provided

Project description

Pybind11 bindings for whisper.cpp

Quickstart

Install with pip:

pip install whispercpp

To use the latest version, install from source:

pip install git+https://github.com/aarnphm/whispercpp.git

For local setup, initialize all submodules:

git submodule update --init --recursive

Build the wheel:

# Option 1: using pypa/build
python3 -m build -w

# Option 2: using bazel
./tools/bazel build //:whispercpp_wheel

Install the wheel:

# Option 1: via pypa/build
pip install dist/*.whl

# Option 2: using bazel
pip install $(./tools/bazel info bazel-bin)/*.whl

The binding provides a Whisper class:

from whispercpp import Whisper

w = Whisper.from_pretrained("tiny.en")

Currently, the inference API is provided via transcribe:

w.transcribe(np.ones((1, 16000)))

You can use ffmpeg or librosa to load audio files into a Numpy array, then pass it to transcribe:

import ffmpeg
import numpy as np

try:
    y, _ = (
        ffmpeg.input("/path/to/audio.wav", threads=0)
        .output("-", format="s16le", acodec="pcm_s16le", ac=1, ar=sample_rate)
        .run(
            cmd=["ffmpeg", "-nostdin"], capture_stdout=True, capture_stderr=True
        )
    )
except ffmpeg.Error as e:
    raise RuntimeError(f"Failed to load audio: {e.stderr.decode()}") from e

arr = np.frombuffer(y, np.int16).flatten().astype(np.float32) / 32768.0

w.transcribe(arr)

The Pybind11 bindings supports all of the features from whisper.cpp.

The binding can also be used via api:

from whispercpp import api

ctx = api.Context.from_file("/path/to/saved_weight.bin")
params = api.Params()

ctx.full(arr, params)

Development

See DEVELOPMENT.md

APIs

Whisper

  1. Whisper.from_pretrained(model_name: str) -> Whisper

    Load a pre-trained model from the local cache or download and cache if needed.

    w = Whisper.from_pretrained("tiny.en")

The model will be saved to $XDG_DATA_HOME/whispercpp or ~/.local/share/whispercpp if the environment variable is not set.

  1. Whisper.transcribe(arr: NDArray[np.float32], num_proc: int = 1)

    Running transcription on a given Numpy array. This calls full from whisper.cpp. If num_proc is greater than 1, it will use full_parallel instead.

    w.transcribe(np.ones((1, 16000)))

api

api is a direct binding from whisper.cpp, that has similar APIs to whisper-rs.

  1. api.Context

    This class is a wrapper around whisper_context

    from whispercpp import api
    
    ctx = api.Context.from_file("/path/to/saved_weight.bin")
  2. api.Params

    This class is a wrapper around whisper_params

    from whispercpp import api
    
    params = api.Params()

Why not?

  • whispercpp.py. There are a few key differences here:

    • They provides the Cython bindings. From the UX standpoint, this achieves the same goal as whispercpp. The difference is whispercpp use Pybind11 instead. Feel free to use it if you prefer Cython over Pybind11. Note that whispercpp.py and whispercpp are mutually exclusive, as they also use the whispercpp namespace.

    • whispercpp doesn’t pollute your $HOME directory, rather it follows the XDG Base Directory Specification for saved weights.

  • Using cdll and ctypes and be done with it?

    • This is also valid, but requires a lot of hacking and it is pretty slow comparing to Cython and Pybind11.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

whispercpp-0.0.16.tar.gz (2.8 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

whispercpp-0.0.16-cp311-cp311-manylinux2014_x86_64.whl (1.5 MB view details)

Uploaded CPython 3.11

whispercpp-0.0.16-cp311-cp311-macosx_10_9_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.11macOS 10.9+ x86-64

whispercpp-0.0.16-cp310-cp310-manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.10

whispercpp-0.0.16-cp310-cp310-macosx_10_9_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.10macOS 10.9+ x86-64

whispercpp-0.0.16-cp39-cp39-manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.9

whispercpp-0.0.16-cp39-cp39-macosx_10_9_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.9macOS 10.9+ x86-64

whispercpp-0.0.16-cp38-cp38-manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.8

whispercpp-0.0.16-cp38-cp38-macosx_10_9_x86_64.whl (1.3 MB view details)

Uploaded CPython 3.8macOS 10.9+ x86-64

File details

Details for the file whispercpp-0.0.16.tar.gz.

File metadata

  • Download URL: whispercpp-0.0.16.tar.gz
  • Upload date:
  • Size: 2.8 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.11.2

File hashes

Hashes for whispercpp-0.0.16.tar.gz
Algorithm Hash digest
SHA256 ca2bc2c0968878f7cb6fb96e2a8713bc8154eacdb5ebb1360205f7902f6f46a7
MD5 dd54b154c4fc39bedcf4b496a927ed14
BLAKE2b-256 ff44fae6f56612ef885e614824973028a4ca9bae48ae6f784614577a8e1c7275

See more details on using hashes here.

File details

Details for the file whispercpp-0.0.16-cp311-cp311-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for whispercpp-0.0.16-cp311-cp311-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 a0c97c5c1a58ead09dc4657226adca57b15ba8b012f3ccec6e673c8add61ff42
MD5 80fd2cafe4ec3c34dd1776c96738903e
BLAKE2b-256 c604fd16404448d0c7fe283492155138d3cd0eafd6f84617404b69b765cda828

See more details on using hashes here.

File details

Details for the file whispercpp-0.0.16-cp311-cp311-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for whispercpp-0.0.16-cp311-cp311-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 804412da36382ee07cb76c0ccca62065c4c7a762048532e232dd79cae8744a15
MD5 ccf2a505b1c5523b7e6e854cf35e94fc
BLAKE2b-256 528456099a99d388e86ab71b7ff861d77b3380b1e4be63f34bd73fb4c9ea6b39

See more details on using hashes here.

File details

Details for the file whispercpp-0.0.16-cp310-cp310-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for whispercpp-0.0.16-cp310-cp310-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 0980a8444013145fac74f883d92ac26875dff8b46fdebdf7008182b638361a8b
MD5 26c2b74f158f436ab5917739f4ba9194
BLAKE2b-256 14193c4e89d91cebb7034bab5b5c21f3ebe2a538bfdc4d04fdf73ac85352b98b

See more details on using hashes here.

File details

Details for the file whispercpp-0.0.16-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for whispercpp-0.0.16-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 7bbfee36148f6876a055b47b832c0df481f7deb33631dc32ba5c2dca4291a8e6
MD5 a54356420fed88485f07fcb7abd53293
BLAKE2b-256 36a7fefbc4569078d31dea536bc66e6f99c5e6a632a72ec95a85f2f9b8f47276

See more details on using hashes here.

File details

Details for the file whispercpp-0.0.16-cp39-cp39-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for whispercpp-0.0.16-cp39-cp39-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ac3b23edf718299ec29c46d5bb479b19b49798f6c60891226d253ae66f9b3534
MD5 83466226c057cbd2365300c96c03f0be
BLAKE2b-256 2acfea3f52504c34304f8defb2c6b5b0d10129572afa812887119362af95a9e8

See more details on using hashes here.

File details

Details for the file whispercpp-0.0.16-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for whispercpp-0.0.16-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 4f115c7e7283721613e2df2c5b2cb2723e3f139285e228abfba347b30a96dfc5
MD5 096afb8d2c050bb549e6e5a95d0ac00d
BLAKE2b-256 1ef068e8fb328513f3f844adec1e7b56e4e00c1a297c17e5bc8dfc950a871d7a

See more details on using hashes here.

File details

Details for the file whispercpp-0.0.16-cp38-cp38-manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for whispercpp-0.0.16-cp38-cp38-manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 35f72c408324ec02fa1c03a773831fbe0bb3ed76153a60c6a699a321efa5d09e
MD5 40511250a77549f14d8af65e56c26a98
BLAKE2b-256 809819a3b1d268686dc04cd77476d526a15bdbb93747af7d21c1e192d46b7ae5

See more details on using hashes here.

File details

Details for the file whispercpp-0.0.16-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for whispercpp-0.0.16-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 1825983dd39700b0382dc00a83a903f4427058a221f3933bb6a68784d5bf8a86
MD5 a3d95d5cc41679a8fe057e6c068d851a
BLAKE2b-256 f38b07a3a07289da0c27c3f4abbae3e6941a95f029c7b1d763eaec8cd6f600e1

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