@choewy/whisper
v1.0.11
Published
Whisper Node.js Wrapper
Readme
@choewy/whisper
A Node.js wrapper around whisper.cpp for local speech-to-text.
This package bundles vendor/whisper.cpp and runs whisper-cli under the hood.
Features
- Simple
Whisperclass API for Node.js/TypeScript - Interactive model downloader via CLI
- Auto-build attempt (
make) whenwhisper-cliis missing - Transcript parsing to
{ start, end, speech }[] - Optional
.txt,.srt,.vttgeneration flags
Installation
npm install @choewy/whisperpnpm install @choewy/whisperRequirements
Depending on your environment, install:
makeand a C/C++ toolchaincurl,wget, orwget2(for model download script)
MacOS
brew install cmake wgetUbuntu/Debian
sudo apt update
sudo apt install -y cmake build-essentialQuick Start
1. Download a model
npx @choewy/whisper downloador
pnpx @choewy/whisper download2. Transcribe an audio file
import { Whisper } from '@choewy/whisper';
async function main() {
const whisper = new Whisper({
model: 'small',
gpu: false,
flashAttention: false,
});
await whisper.initialize();
const lines = await whisper.transcribe('./audio.wav', {
language: 'auto',
wordTimestamps: true,
});
console.log(lines);
}
void main();CLI
download
Interactive model picker + download + build:
npx @choewy/whisper downloadpnpx @choewy/whisper download--help
npx @choewy/whisper --helppnpx @choewy/whisper --helpAPI
new Whisper(options?)
Creates a Whisper instance.
WhisperOptions:
| Option | Type | Default* | Description |
| ---------------- | ------------------------------------------------------------------------------------------------------------------------- | --------- | -------------------------------------------- |
| model | 'tiny' \| 'tiny.en' \| 'base' \| 'base.en' \| 'small' \| 'small.en' \| 'medium' \| 'medium.en' \| 'large' \| 'large-v1' | 'base' | Whisper model name |
| gpu | boolean | false | Enable GPU execution |
| gpuDevice | number | 0 | GPU device index (requires GPU) |
| flashAttention | boolean | false | Enable flash-attention flag |
| debug | boolean | true | Print subprocess stdout/stderr |
| async | boolean | true | Reserved option (no external behavior today) |
*Defaults apply only when new Whisper() is called with no arguments.
Note: this constructor does not merge partial options with defaults. If you pass an object, provide all options you rely on.
await whisper.initialize(): Promise<Whisper>
- Verifies model name
- Downloads the selected model if missing
- Compiles
whisper.cpp(make) when needed
await whisper.transcribe(input, options?): Promise<WhisperTranscriptLine[]>
input: path to an audio fileoptions: whisper command options
WhisperCppCommandInputOptions:
| Option | Type | Flag | Description |
| ---------------------- | --------- | ----------- | -------------------------------- |
| generateFileText | boolean | -otxt | Generate .txt output |
| generateFileSubtitle | boolean | -osrt | Generate .srt output |
| generateFileVtt | boolean | -ovtt | Generate .vtt output |
| timestampSize | number | -ml N | Segment length control |
| wordTimestamps | boolean | -ml 1 | Very fine-grained segmentation |
| language | string | -l <lang> | Language code (auto supported) |
Constraints:
timestampSizeandwordTimestampscannot be used togethergpuDevicerequiresgpu: true
Return type:
type WhisperTranscriptLine = {
start: string;
end: string;
speech: string;
};Supported Models
| Model | Disk | RAM |
| ----------- | -----: | ------: |
| tiny | 75 MB | ~390 MB |
| tiny.en | 75 MB | ~390 MB |
| base | 142 MB | ~500 MB |
| base.en | 142 MB | ~500 MB |
| small | 466 MB | ~1.0 GB |
| small.en | 466 MB | ~1.0 GB |
| medium | 1.5 GB | ~2.6 GB |
| medium.en | 1.5 GB | ~2.6 GB |
| large | 2.9 GB | ~4.7 GB |
| large-v1 | 2.9 GB | ~4.7 GB |
Notes
transcribe()executeswhisper-clias a subprocess.- This wrapper exposes only part of
whisper.cppCLI options. - For advanced flags and behavior, see upstream docs:
Troubleshooting
Command not found: make
Install make and build tools on your system.
Model download failed
Install at least one of curl, wget, wget2 and check network/proxy settings.
GPU device option error
Do not set gpuDevice when gpu is false.
