@drakulavich/parakeet-cli 0.2.0 → 0.3.0

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.
package/package.json CHANGED
@@ -1,11 +1,15 @@
1
1
  {
2
2
  "name": "@drakulavich/parakeet-cli",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Fast multilingual speech-to-text CLI powered by NVIDIA Parakeet ONNX models",
5
5
  "type": "module",
6
6
  "bin": {
7
7
  "parakeet": "bin/parakeet.js"
8
8
  },
9
+ "exports": {
10
+ ".": "./src/cli.ts",
11
+ "./core": "./src/lib.ts"
12
+ },
9
13
  "files": [
10
14
  "bin/",
11
15
  "src/",
@@ -0,0 +1,12 @@
1
+ import { describe, expect, it } from "bun:test";
2
+ import { transcribe } from "../lib";
3
+
4
+ describe("lib API", () => {
5
+ it("exports transcribe function", () => {
6
+ expect(typeof transcribe).toBe("function");
7
+ });
8
+
9
+ it("rejects missing file", async () => {
10
+ await expect(transcribe("/nonexistent/audio.wav")).rejects.toThrow("File not found");
11
+ });
12
+ });
package/src/cli.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  #!/usr/bin/env bun
2
2
 
3
- import { existsSync } from "fs";
4
- import { transcribe } from "./transcribe";
3
+ import { transcribe } from "./lib";
5
4
 
6
5
  async function main(): Promise<void> {
7
6
  const args = process.argv.slice(2);
@@ -20,11 +19,6 @@ async function main(): Promise<void> {
20
19
  process.exit(1);
21
20
  }
22
21
 
23
- if (!existsSync(file)) {
24
- console.error(`Error: file not found: ${file}`);
25
- process.exit(1);
26
- }
27
-
28
22
  try {
29
23
  const text = await transcribe(file, { noCache });
30
24
  if (text) process.stdout.write(text + "\n");
package/src/lib.ts ADDED
@@ -0,0 +1,23 @@
1
+ import { existsSync } from "fs";
2
+ import { transcribe as internalTranscribe } from "./transcribe";
3
+
4
+ export interface TranscribeOptions {
5
+ beamWidth?: number;
6
+ noCache?: boolean;
7
+ modelDir?: string;
8
+ }
9
+
10
+ export async function transcribe(
11
+ audioPath: string,
12
+ options: TranscribeOptions = {},
13
+ ): Promise<string> {
14
+ if (!existsSync(audioPath)) {
15
+ throw new Error(`File not found: ${audioPath}`);
16
+ }
17
+
18
+ return internalTranscribe(audioPath, {
19
+ noCache: options.noCache ?? false,
20
+ beamWidth: options.beamWidth,
21
+ modelDir: options.modelDir,
22
+ });
23
+ }
package/src/models.ts CHANGED
@@ -16,13 +16,13 @@ export function getModelDir(): string {
16
16
  return join(homedir(), ".cache", "parakeet", "v3");
17
17
  }
18
18
 
19
- export function isModelCached(): boolean {
20
- const dir = getModelDir();
21
- return MODEL_FILES.every((f) => existsSync(join(dir, f)));
19
+ export function isModelCached(dir?: string): boolean {
20
+ const d = dir ?? getModelDir();
21
+ return MODEL_FILES.every((f) => existsSync(join(d, f)));
22
22
  }
23
23
 
24
- export async function ensureModel(noCache = false): Promise<string> {
25
- const dir = getModelDir();
24
+ export async function ensureModel(noCache = false, modelDir?: string): Promise<string> {
25
+ const dir = modelDir ?? getModelDir();
26
26
 
27
27
  if (!noCache && isModelCached()) {
28
28
  return dir;
package/src/transcribe.ts CHANGED
@@ -26,6 +26,8 @@ const DECODER_HIDDEN = 640;
26
26
 
27
27
  export interface TranscribeOptions {
28
28
  noCache?: boolean;
29
+ beamWidth?: number;
30
+ modelDir?: string;
29
31
  }
30
32
 
31
33
  // Minimum 0.1s of audio at 16kHz to produce meaningful output
@@ -39,7 +41,8 @@ export async function transcribe(audioPath: string, opts: TranscribeOptions = {}
39
41
  }
40
42
 
41
43
  const noCache = opts.noCache ?? false;
42
- const modelDir = await ensureModel(noCache);
44
+ const beamWidth = opts.beamWidth ?? 4;
45
+ const modelDir = await ensureModel(noCache, opts.modelDir);
43
46
  const tokenizer = await Tokenizer.fromFile(join(modelDir, "vocab.txt"));
44
47
 
45
48
  await initPreprocessor(modelDir);
@@ -63,6 +66,6 @@ export async function transcribe(audioPath: string, opts: TranscribeOptions = {}
63
66
  DECODER_HIDDEN,
64
67
  );
65
68
 
66
- const tokens = await beamDecode(session, encodedLength, transposed, D);
69
+ const tokens = await beamDecode(session, encodedLength, transposed, D, beamWidth);
67
70
  return tokenizer.detokenize(tokens);
68
71
  }