@spader/node-whisper-cpp 0.0.1 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,11 @@
1
+ import type { ContextOptions, Segment, TranscribeOptions } from "./types.js";
2
+ export type { ContextOptions, Segment, TranscribeOptions };
3
+ export declare function version(): string;
4
+ export declare function systemInfo(): string;
5
+ export declare function createContext(options: ContextOptions): Context;
6
+ export declare class Context {
7
+ private readonly native;
8
+ constructor(options: ContextOptions);
9
+ transcribe(options: TranscribeOptions): Promise<Segment[]>;
10
+ free(): void;
11
+ }
package/dist/index.js ADDED
@@ -0,0 +1,22 @@
1
+ import { loadAddon } from "./loader.js";
2
+ export function version() {
3
+ return loadAddon().version();
4
+ }
5
+ export function systemInfo() {
6
+ return loadAddon().systemInfo();
7
+ }
8
+ export function createContext(options) {
9
+ return new Context(options);
10
+ }
11
+ export class Context {
12
+ native;
13
+ constructor(options) {
14
+ this.native = new (loadAddon().WhisperContext)(options);
15
+ }
16
+ transcribe(options) {
17
+ return this.native.transcribe(options);
18
+ }
19
+ free() {
20
+ this.native.free();
21
+ }
22
+ }
@@ -0,0 +1,2 @@
1
+ import type { NativeAddon } from "./types.js";
2
+ export declare function loadAddon(): NativeAddon;
package/dist/loader.js ADDED
@@ -0,0 +1,50 @@
1
+ import { createRequire } from "node:module";
2
+ import { platform, arch } from "node:process";
3
+ import { dirname, join } from "node:path";
4
+ import { fileURLToPath } from "node:url";
5
+ const require = createRequire(import.meta.url);
6
+ const currentDir = dirname(fileURLToPath(import.meta.url));
7
+ const platformPackages = {
8
+ "darwin-arm64": "@spader/node-whisper-cpp-mac-arm64-metal",
9
+ "linux-x64": "@spader/node-whisper-cpp-linux-x64-cpu",
10
+ };
11
+ const localPlatformDirs = {
12
+ "@spader/node-whisper-cpp-mac-arm64-metal": "mac-arm64-metal",
13
+ "@spader/node-whisper-cpp-linux-x64-cpu": "linux-x64-cpu",
14
+ };
15
+ function getPlatformKey() {
16
+ return `${platform}-${arch}`;
17
+ }
18
+ function resolvePlatformPackageName() {
19
+ const platformKey = getPlatformKey();
20
+ const packageName = platformPackages[platformKey];
21
+ if (packageName) {
22
+ return packageName;
23
+ }
24
+ throw new Error(`Unsupported platform ${platformKey}. Supported platforms: ${Object.keys(platformPackages).join(", ")}`);
25
+ }
26
+ function resolvePlatformPackageDir(packageName) {
27
+ try {
28
+ const entryPath = require.resolve(packageName);
29
+ return join(dirname(entryPath), "..");
30
+ }
31
+ catch {
32
+ const packageDirName = localPlatformDirs[packageName];
33
+ if (packageDirName == null) {
34
+ throw new Error(`No local package directory mapping for ${packageName}`);
35
+ }
36
+ return join(currentDir, "..", "packages", "platform", packageDirName);
37
+ }
38
+ }
39
+ let addonCache = null;
40
+ export function loadAddon() {
41
+ if (addonCache != null) {
42
+ return addonCache;
43
+ }
44
+ const packageName = resolvePlatformPackageName();
45
+ const packageDir = resolvePlatformPackageDir(packageName);
46
+ const binsDir = join(packageDir, "bins");
47
+ const addonPath = join(binsDir, "whisper-addon.node");
48
+ addonCache = require(addonPath);
49
+ return addonCache;
50
+ }
@@ -0,0 +1,26 @@
1
+ export interface ContextOptions {
2
+ model: string;
3
+ use_gpu?: boolean;
4
+ flash_attn?: boolean;
5
+ gpu_device?: number;
6
+ }
7
+ export interface Segment {
8
+ t0: number;
9
+ t1: number;
10
+ text: string;
11
+ }
12
+ export interface TranscribeOptions {
13
+ pcm: Float32Array;
14
+ language?: string;
15
+ threads?: number;
16
+ onSegment?: (segment: Segment) => void;
17
+ }
18
+ export interface NativeContext {
19
+ transcribe(options: TranscribeOptions): Promise<Segment[]>;
20
+ free(): void;
21
+ }
22
+ export interface NativeAddon {
23
+ WhisperContext: new (options: ContextOptions) => NativeContext;
24
+ version(): string;
25
+ systemInfo(): string;
26
+ }
package/dist/types.js ADDED
@@ -0,0 +1 @@
1
+ export {};
package/package.json CHANGED
@@ -1,6 +1,54 @@
1
1
  {
2
2
  "name": "@spader/node-whisper-cpp",
3
- "version": "0.0.1",
4
- "description": "placeholder",
5
- "publishConfig": { "access": "public" }
3
+ "version": "0.0.7",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js",
11
+ "default": "./dist/index.js"
12
+ }
13
+ },
14
+ "imports": {
15
+ "#tools/build": "./tools/build.ts"
16
+ },
17
+ "files": [
18
+ "dist/",
19
+ "packages/platform/mac-arm64-metal/",
20
+ "packages/platform/linux-x64-cpu/",
21
+ "package.json"
22
+ ],
23
+ "scripts": {
24
+ "build": "bun run ./tools/build.ts system",
25
+ "build:mac-arm64": "bun run ./tools/build.ts all --os mac --arch arm64 --backend metal",
26
+ "build:linux-x64": "bun run ./tools/build.ts all --os linux --arch x64 --backend cpu",
27
+ "ci": "bun run ./tools/ci.ts install",
28
+ "test": "bun test ./test/smoke.test.ts",
29
+ "clean": "bun run ./tools/clean.ts"
30
+ },
31
+ "optionalDependencies": {
32
+ "@spader/node-whisper-cpp-mac-arm64-metal": "0.0.7",
33
+ "@spader/node-whisper-cpp-linux-x64-cpu": "0.0.7"
34
+ },
35
+ "repository": {
36
+ "type": "git",
37
+ "url": "https://github.com/tspader/node-whisper-cpp"
38
+ },
39
+ "publishConfig": {
40
+ "access": "public"
41
+ },
42
+ "dependencies": {
43
+ "node-addon-api": "^8.3.1"
44
+ },
45
+ "devDependencies": {
46
+ "@clack/prompts": "^1.0.0",
47
+ "@types/bun": "^1.2.21",
48
+ "@types/node": "^24.3.0",
49
+ "@types/yargs": "^17.0.35",
50
+ "cmake-js": "^7.3.0",
51
+ "typescript": "^5.9.3",
52
+ "yargs": "^18.0.0"
53
+ }
6
54
  }