Skip to main content

A simple Python wrapper for whisper.cpp

Project description

Simpler Whisper

Build and Test

A zero-dependency simple Python wrapper for whisper.cpp, providing an easy-to-use interface for speech recognition using the Whisper model.

Why is it better than faster-whisper and pywhispercpp:

  • Zero-dependency: Everything is shipped with the built wheel, no Python dependency (on av or ctranslate2 etc.) except for numpy.
  • Dead simple API: call .transcribe() and get a result
  • Acceleration enabled: supports whatever whisper.cpp supports
  • Updated: using precompiled whisper.cpp from https://github.com/locaal-ai/occ-ai-dep-whispercpp
  • Build time: builds in 2 minutes because it's using a precompiled binary

Installation

To install simpler-whisper, you need:

  • A C++ compiler (e.g., GCC, Clang, or MSVC)
  • CMake (version 3.12 or higher)
  • NumPy

Then you can install using pip:

pip install simpler-whisper

Usage

There are three ways to use simpler-whisper:

1. Basic Usage

from simpler_whisper.whisper import WhisperModel

# Load the model (models can be downloaded from https://huggingface.co/ggerganov/whisper.cpp)
model = WhisperModel("path/to/model.bin", use_gpu=True)

# Load and prepare your audio
# You can use av, librosa, or any method that gives you 16kHz mono float32 samples
import av
container = av.open("audio.mp3")
audio_stream = container.streams.audio[0]
samples = np.concatenate([
    frame.to_ndarray().mean(axis=0) if frame.format.channels == 2 else frame.to_ndarray()
    for frame in container.decode(audio_stream)
])

# Transcribe
transcription = model.transcribe(samples)
for segment in transcription:
    print(f"{segment.text} ({segment.t0:.2f}s - {segment.t1:.2f}s)")

2. Async Processing

This will create a thread in the backend (not locked by the GIL) to allow for asynchronous transcription.

from simpler_whisper.whisper import AsyncWhisperModel

def handle_result(chunk_id: int, segments: List[WhisperSegment], is_partial: bool):
    text = " ".join([seg.text for seg in segments])
    print(f"Chunk {chunk_id}: {text}")

# Create and start async model
model = AsyncWhisperModel("path/to/model.bin", callback=handle_result, use_gpu=True)
model.start()

# Queue audio chunks for processing
chunk_id = model.transcribe(audio_samples)

# When done
model.stop()

3. Real-time Threaded Processing

This method creates a background thread for real-time transcription that will continuously process the input in e.g. 10 seconds chunks and report on both final or partial results.

from simpler_whisper.whisper import ThreadedWhisperModel

def handle_result(chunk_id: int, segments: List[WhisperSegment], is_partial: bool):
    text = " ".join([seg.text for seg in segments])
    print(f"Chunk {chunk_id}: {text}")

# Create and start threaded model with 10-second chunks
model = ThreadedWhisperModel(
    "path/to/model.bin",
    callback=handle_result,
    use_gpu=True,
    max_duration_sec=10.0
)
model.start()

# Queue audio chunks as they arrive
chunk_id = model.queue_audio(audio_samples)

# When done
model.stop()

Platform-specific notes

  • On Windows, the package uses a DLL (whisper.dll), which is included in the package.
  • On Mac and Linux, the package uses static libraries that are linked into the extension.

Building from source

If you're building from source:

  1. Clone the repository:
    git clone https://github.com/locaal-ai/simpler-whisper.git
    cd simpler-whisper
    
  2. Install the package in editable mode:
    pip install -e .
    

This will run the CMake build process and compile the extension.

Build Configuration

Simpler Whisper supports various build configurations to optimize for different hardware and acceleration methods. You can specify the build configuration using environment variables:

  • SIMPLER_WHISPER_ACCELERATION: Specifies the acceleration method. Options are:
    • cpu (default)
    • cuda (for NVIDIA GPUs)
    • hipblas (for AMD GPUs)
    • vulkan (for cross-platform GPU acceleration)

Example: Building for Windows with CUDA acceleration

$env:SIMPLER_WHISPER_ACCELERATION="cuda"
pip install .

Example: Building for macOS ARM64

pip install .

License

This project is licensed under the MIT License - see the LICENSE file 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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

simpler_whisper-0.2.4.post3-cp312-cp312-win_amd64.whl (13.2 MB view details)

Uploaded CPython 3.12Windows x86-64

simpler_whisper-0.2.4.post3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (2.1 MB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ x86-64

simpler_whisper-0.2.4.post3-cp312-cp312-macosx_10_13_universal2.whl (4.2 MB view details)

Uploaded CPython 3.12macOS 10.13+ universal2 (ARM64, x86-64)

simpler_whisper-0.2.4.post3-cp311-cp311-win_amd64.whl (13.2 MB view details)

Uploaded CPython 3.11Windows x86-64

simpler_whisper-0.2.4.post3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ x86-64

simpler_whisper-0.2.4.post3-cp311-cp311-macosx_10_13_universal2.whl (2.8 MB view details)

Uploaded CPython 3.11macOS 10.13+ universal2 (ARM64, x86-64)

simpler_whisper-0.2.4.post3-cp310-cp310-win_amd64.whl (13.2 MB view details)

Uploaded CPython 3.10Windows x86-64

simpler_whisper-0.2.4.post3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (735.1 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.17+ x86-64

simpler_whisper-0.2.4.post3-cp310-cp310-macosx_10_13_universal2.whl (1.4 MB view details)

Uploaded CPython 3.10macOS 10.13+ universal2 (ARM64, x86-64)

File details

Details for the file simpler_whisper-0.2.4.post3-cp312-cp312-win_amd64.whl.

File metadata

File hashes

Hashes for simpler_whisper-0.2.4.post3-cp312-cp312-win_amd64.whl
Algorithm Hash digest
SHA256 1959e56da5576f794c3c07b48a6ada5eb1816d66b83686271091d385bdee1c92
MD5 0633f5c6432dcacd6694c884bbeb3aac
BLAKE2b-256 5e16fb81da6e72d21ae54dd348efbbe1f1ab1dd045d0f6d50ea3d69399d7a959

See more details on using hashes here.

File details

Details for the file simpler_whisper-0.2.4.post3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for simpler_whisper-0.2.4.post3-cp312-cp312-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d671760e0f1e139e2155743ef0955b81ce9ebdfa0794da1d10f47cc0d420910e
MD5 1d569a7114b9d14121d7b0122f4f5e6b
BLAKE2b-256 46a5da79e4d299d792fcc391f68e540427222732a0a3e77be68039204baba3e0

See more details on using hashes here.

File details

Details for the file simpler_whisper-0.2.4.post3-cp312-cp312-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for simpler_whisper-0.2.4.post3-cp312-cp312-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 cbd02f4a80a3d0fe492e1aa6cc54b16d22d85b7260cb151fa24e7a8cc38957eb
MD5 28081dd0da6ef317cd9902e15dbbf80d
BLAKE2b-256 810bf3340e32578be77ca5b63765b981b33a9020ad1cd5ccab73fd488d2c9e82

See more details on using hashes here.

File details

Details for the file simpler_whisper-0.2.4.post3-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for simpler_whisper-0.2.4.post3-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 19c56c921c7ed7e392fa4b4e3244841ff5713de40782c9043995d238ee8c1e14
MD5 468c9dc65c8b68d684cf3518aa52009b
BLAKE2b-256 f61cf71d97b9668058084c3bc366d967880d023c510393f4e2fd6001e648a7d7

See more details on using hashes here.

File details

Details for the file simpler_whisper-0.2.4.post3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for simpler_whisper-0.2.4.post3-cp311-cp311-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 3b63aae100d4d9bb7a0e49d8b3c05d04c18a9218b25157b87c7d1f34ec73741d
MD5 a227272026c99d41a361281fcb93095c
BLAKE2b-256 550b6dd336ab39c7cd06a32ab849f8e4de7926d8b0f5048a17fc3d99e65acda7

See more details on using hashes here.

File details

Details for the file simpler_whisper-0.2.4.post3-cp311-cp311-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for simpler_whisper-0.2.4.post3-cp311-cp311-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 90fb6b30b01a624cf7e0a59ac39c9bc60fc7e89d6ff4c74b94459de380b4b4df
MD5 e82347cc774e26220eac07350727db23
BLAKE2b-256 5b92e47798ed7f0ec8f9f1e6d71ee573855d2644bf4a7b3d5efaff1f33af9a88

See more details on using hashes here.

File details

Details for the file simpler_whisper-0.2.4.post3-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for simpler_whisper-0.2.4.post3-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 8cdb6a29f6a5ad00f98e2620258351687c942b591a8c0393d5449a03f70ddaea
MD5 955c703cc0fff7f27eb806dda0513451
BLAKE2b-256 e1076dbe2dcbec100d084fbe7bed2432bd5f2424f427b4f07d289c2d3e5ec5e7

See more details on using hashes here.

File details

Details for the file simpler_whisper-0.2.4.post3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for simpler_whisper-0.2.4.post3-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 165f355cadd8063a20b6b623918c0fdf7098c2d4d9dd0c6dd9bf2f13d0969b3f
MD5 0a60a1fa6b32c5fbe17b3c44dfa0680f
BLAKE2b-256 19e2cb88c90269bbc20f8b1b7cfa740e311084e8d49da9fbe6a6e6e0086a0431

See more details on using hashes here.

File details

Details for the file simpler_whisper-0.2.4.post3-cp310-cp310-macosx_10_13_universal2.whl.

File metadata

File hashes

Hashes for simpler_whisper-0.2.4.post3-cp310-cp310-macosx_10_13_universal2.whl
Algorithm Hash digest
SHA256 3e24d4c84de9810adaf6713d9e1321563b72029bba7bf9a0612c225d67f690d4
MD5 49dccfb21a721e72ac186a4dd5f423da
BLAKE2b-256 ba91df531c22b6d8dd83bca732be9128de8d44294402667b209251b751bf7c1c

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