No description
Find a file
2024-12-11 22:18:30 -08:00
samples Fix (bindings): Fixes to high level and low level bindings 2023-11-26 17:43:54 -08:00
src Chore: Update whisper 2024-12-11 22:08:02 -08:00
tests Fix (Lifetime-tracking hooks): Improve lifetime tracking hooks 2024-10-31 22:45:55 -07:00
.gitignore Feat: Add translation support. 2023-12-09 21:16:06 -08:00
.gitmodules Feat: Transition to using Futhark. 2024-06-27 23:49:22 -07:00
LICENSE Initial commit 2023-11-26 17:43:02 -08:00
README.md Chore: Update README 2023-12-15 22:15:49 -08:00
whisper.nimble Chore: Bump version 2024-12-11 22:18:30 -08:00

Nim bindings for libwhisper

This package provides Nim bindings for libwhisper (1.5.0+) (AKA Whisper.cpp).

There are two major bindings:

  • simple bindings
  • higher level Nim wrapped bindings

The simple bindings expose the entirety of the libwhisper C API to Nim, while the higher level Nim wrapped bindings provide simpler but limited functionality.

Example

Using the high level bindings, we can run inference on a 16-bit WAV files, with the default libwhisper parameters. The high level bindings use Nim's lifetime tracking hooks, so users need don't need to manually free resources.

import whisper/highlevel

let 
    options = newDefaultOptions("ggml-base.en.bin")
    w = newWhisper(options)
    result = w.infer("samples/jfk.wav")

The equivalent using the simple bindings is more cumbersome, but is a one-to-one mapping of the C API.

import whisper/bindings

let file = "ggml-base.en.bin".cstring
var 
    params = whisperContextDefaultParams()
    ctx = whisperInitFromFileWithParams(file, params)
    fullParams = whisperFullDefaultParams(WHISPER_SAMPLING_GREEDY)
# Read 16-bit WAV file into bufffer (ptr cfloat)
# bufferLen contains the size of the buffer
whisperFull(ctx, fullParams, buffer, bufferLen)
whisperFree(ctx) # Free libwhisper context