Skip to main content

Python bindings for transcribe.cpp

Project description

transcribe-cpp

Python bindings for transcribe.cpp, a C/C++ speech-to-text library built on ggml.

Status: in development. Until wheels are published, use a locally built libtranscribe through repo auto-discovery or TRANSCRIBE_LIBRARY.

import transcribe_cpp

with transcribe_cpp.Model("model.gguf") as model:
    with model.session() as session:
        result = session.run(pcm_float32_16k_mono)
        print(result.text)

run() takes mono 16 kHz float32 PCM (buffer-protocol object or sequence). It does not decode containers or resample; convert audio before calling it.

import numpy as np

pcm = np.asarray(audio, dtype=np.float32)   # 1-D, 16 kHz mono
# Downmix stereo first; 2-D input is rejected:
# pcm = audio.mean(axis=1).astype(np.float32)
result = session.run(pcm)

Streaming models expose incremental transcription with committed/tentative text views — see examples/stream_wav.py:

with model.session() as session, session.stream() as stream:
    for chunk in pcm_chunks:
        stream.feed(chunk)
        text = stream.text()        # .committed (stable) + .tentative
    stream.finalize()

Long transcriptions can be cancelled from another thread with session.cancel() — the run raises Aborted with the partial transcript on exc.partial_result (same for OutputTruncated).

Backends

Model(backend=...) picks the compute device ("auto" uses the best available). transcribe_cpp.backends() lists registered backends and backend_available(kind) checks one kind.

Variable Effect
TRANSCRIBE_BACKEND overrides the "auto" default; explicit backend= still wins
TRANSCRIBE_NATIVE_PROVIDER forces an installed native provider package, for example cu12
TRANSCRIBE_LIBRARY loads exactly this shared library

Planned wheels will bundle CPU plus platform accelerators; transcribe-cpp[cu12] will add the CUDA 12 provider.

Running from a working tree

The binding loads the native library at import and verifies its ABI layout and version before use. Build a shared library, then run from the repo or point TRANSCRIBE_LIBRARY at it:

cmake -B build-shared -DTRANSCRIBE_BUILD_SHARED=ON
cmake --build build-shared --target transcribe

cd bindings/python
PYTHONPATH=src uv run --no-project python examples/transcribe_wav.py \
    ../../models/whisper-tiny.en/whisper-tiny.en-Q5_K_M.gguf ../../samples/jfk.wav

No-model tests always run; model tests skip unless smoke assets are present. Override paths with TRANSCRIBE_SMOKE_MODEL, TRANSCRIBE_SMOKE_AUDIO, and TRANSCRIBE_SMOKE_STREAMING_MODEL.

cd bindings/python
TRANSCRIBE_LIBRARY=../../build-shared/src/libtranscribe.dylib \
    uv run --extra test pytest

Notes

  • One run/stream at a time per Model in 0.x: sessions share the model's compute backend, so serialize runs across sessions (or load one model per worker). See the Model docstring.
  • Import package: transcribe_cpp
  • Distribution: transcribe-cpp
  • License: MIT

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

transcribe_cpp-0.0.7.tar.gz (87.4 kB view details)

Uploaded Source

Built Distribution

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

transcribe_cpp-0.0.7-py3-none-any.whl (32.5 kB view details)

Uploaded Python 3

File details

Details for the file transcribe_cpp-0.0.7.tar.gz.

File metadata

  • Download URL: transcribe_cpp-0.0.7.tar.gz
  • Upload date:
  • Size: 87.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for transcribe_cpp-0.0.7.tar.gz
Algorithm Hash digest
SHA256 adbf039dc054503b0ef4ac880c66115044d90179137e641cda52194e54a9c0d6
MD5 f2720a3158ab0385ee9d0315c6ae4500
BLAKE2b-256 c20f99d7aa274d4ec39a428ffc92966feb35256a607d2a17f13a7dc30fe30e3b

See more details on using hashes here.

Provenance

The following attestation bundles were made for transcribe_cpp-0.0.7.tar.gz:

Publisher: publish.yml on handy-computer/transcribe.cpp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file transcribe_cpp-0.0.7-py3-none-any.whl.

File metadata

  • Download URL: transcribe_cpp-0.0.7-py3-none-any.whl
  • Upload date:
  • Size: 32.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for transcribe_cpp-0.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 48555b5360f4c1e6c8c032239f8f9bdaf5be14d26c10d88aed30a93930502507
MD5 a0b83e5ab0a061d7c943cd6fe3d99e65
BLAKE2b-256 06f4c62ff46ff4be342fd1a2e3f9ad9679fd159dba82da66eac5d453b46aad0c

See more details on using hashes here.

Provenance

The following attestation bundles were made for transcribe_cpp-0.0.7-py3-none-any.whl:

Publisher: publish.yml on handy-computer/transcribe.cpp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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