transcribe-cpp 0.2.3 → 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/README.md CHANGED
@@ -46,6 +46,17 @@ and streams.
46
46
  const result = await model.transcribe(pcm, { pnc: "off", itn: "on" });
47
47
  ```
48
48
 
49
+ ### Prompting
50
+
51
+ `vocabulary` (custom terms), `prompt` (context, or the instruction under
52
+ `task: "instruct"`) and `prefix` (text the model continues from) take effect
53
+ where `model.supports()` reports `"vocabulary"`, `"context_prompt"`,
54
+ `"instruct"` or `"transcript_prefix"`.
55
+
56
+ ```ts
57
+ const result = await model.transcribe(pcm, { vocabulary: ["Kubernetes", "gRPC"] });
58
+ ```
59
+
49
60
  ### Streaming
50
61
 
51
62
  ```ts
@@ -1,4 +1,4 @@
1
- export declare const PUBLIC_HEADER_HASH = "7df72bf9e667b8c2";
1
+ export declare const PUBLIC_HEADER_HASH = "59b9a92b47074666";
2
2
  export declare const TRANSCRIBE_OK = 0;
3
3
  export declare const TRANSCRIBE_ERR_INVALID_ARG = 1;
4
4
  export declare const TRANSCRIBE_ERR_NOT_IMPLEMENTED = 2;
@@ -18,6 +18,7 @@ export declare const TRANSCRIBE_ERR_UNSUPPORTED_PNC = 15;
18
18
  export declare const TRANSCRIBE_ERR_UNSUPPORTED_ITN = 16;
19
19
  export declare const TRANSCRIBE_ERR_INPUT_TOO_LONG = 17;
20
20
  export declare const TRANSCRIBE_ERR_OUTPUT_TRUNCATED = 18;
21
+ export declare const TRANSCRIBE_ERR_OUTPUT_REPETITION = 19;
21
22
  export declare const TRANSCRIBE_ABI_MODEL_LOAD_PARAMS = 0;
22
23
  export declare const TRANSCRIBE_ABI_SESSION_PARAMS = 1;
23
24
  export declare const TRANSCRIBE_ABI_RUN_PARAMS = 2;
@@ -41,6 +42,7 @@ export declare const TRANSCRIBE_LOG_LEVEL_DEBUG = 4;
41
42
  export declare const TRANSCRIBE_LOG_LEVEL_CONT = 5;
42
43
  export declare const TRANSCRIBE_TASK_TRANSCRIBE = 0;
43
44
  export declare const TRANSCRIBE_TASK_TRANSLATE = 1;
45
+ export declare const TRANSCRIBE_TASK_INSTRUCT = 2;
44
46
  export declare const TRANSCRIBE_TIMESTAMPS_NONE = 0;
45
47
  export declare const TRANSCRIBE_TIMESTAMPS_AUTO = 1;
46
48
  export declare const TRANSCRIBE_TIMESTAMPS_SEGMENT = 2;
@@ -78,6 +80,10 @@ export declare const TRANSCRIBE_FEATURE_CANCELLATION = 3;
78
80
  export declare const TRANSCRIBE_FEATURE_PNC = 4;
79
81
  export declare const TRANSCRIBE_FEATURE_ITN = 5;
80
82
  export declare const TRANSCRIBE_FEATURE_DIARIZATION = 6;
83
+ export declare const TRANSCRIBE_FEATURE_VOCABULARY = 7;
84
+ export declare const TRANSCRIBE_FEATURE_CONTEXT_PROMPT = 8;
85
+ export declare const TRANSCRIBE_FEATURE_INSTRUCT = 9;
86
+ export declare const TRANSCRIBE_FEATURE_TRANSCRIPT_PREFIX = 10;
81
87
  export declare const TRANSCRIBE_STREAM_IDLE = 0;
82
88
  export declare const TRANSCRIBE_STREAM_ACTIVE = 1;
83
89
  export declare const TRANSCRIBE_STREAM_FINISHED = 2;
@@ -10,7 +10,7 @@
10
10
  // Stable digest of the ABI surface (structs, enums, macros, layout,
11
11
  // prototypes), computed by the Python oracle and pinned here so a header
12
12
  // ABI change turns this binding's drift check red for conscious review.
13
- export const PUBLIC_HEADER_HASH = "7df72bf9e667b8c2";
13
+ export const PUBLIC_HEADER_HASH = "59b9a92b47074666";
14
14
  // === enum constants ===
15
15
  export const TRANSCRIBE_OK = 0;
16
16
  export const TRANSCRIBE_ERR_INVALID_ARG = 1;
@@ -31,6 +31,7 @@ export const TRANSCRIBE_ERR_UNSUPPORTED_PNC = 15;
31
31
  export const TRANSCRIBE_ERR_UNSUPPORTED_ITN = 16;
32
32
  export const TRANSCRIBE_ERR_INPUT_TOO_LONG = 17;
33
33
  export const TRANSCRIBE_ERR_OUTPUT_TRUNCATED = 18;
34
+ export const TRANSCRIBE_ERR_OUTPUT_REPETITION = 19;
34
35
  export const TRANSCRIBE_ABI_MODEL_LOAD_PARAMS = 0;
35
36
  export const TRANSCRIBE_ABI_SESSION_PARAMS = 1;
36
37
  export const TRANSCRIBE_ABI_RUN_PARAMS = 2;
@@ -54,6 +55,7 @@ export const TRANSCRIBE_LOG_LEVEL_DEBUG = 4;
54
55
  export const TRANSCRIBE_LOG_LEVEL_CONT = 5;
55
56
  export const TRANSCRIBE_TASK_TRANSCRIBE = 0;
56
57
  export const TRANSCRIBE_TASK_TRANSLATE = 1;
58
+ export const TRANSCRIBE_TASK_INSTRUCT = 2;
57
59
  export const TRANSCRIBE_TIMESTAMPS_NONE = 0;
58
60
  export const TRANSCRIBE_TIMESTAMPS_AUTO = 1;
59
61
  export const TRANSCRIBE_TIMESTAMPS_SEGMENT = 2;
@@ -91,6 +93,10 @@ export const TRANSCRIBE_FEATURE_CANCELLATION = 3;
91
93
  export const TRANSCRIBE_FEATURE_PNC = 4;
92
94
  export const TRANSCRIBE_FEATURE_ITN = 5;
93
95
  export const TRANSCRIBE_FEATURE_DIARIZATION = 6;
96
+ export const TRANSCRIBE_FEATURE_VOCABULARY = 7;
97
+ export const TRANSCRIBE_FEATURE_CONTEXT_PROMPT = 8;
98
+ export const TRANSCRIBE_FEATURE_INSTRUCT = 9;
99
+ export const TRANSCRIBE_FEATURE_TRANSCRIPT_PREFIX = 10;
94
100
  export const TRANSCRIBE_STREAM_IDLE = 0;
95
101
  export const TRANSCRIBE_STREAM_ACTIVE = 1;
96
102
  export const TRANSCRIBE_STREAM_FINISHED = 2;
@@ -116,7 +122,7 @@ export const STRUCT_LAYOUT = {
116
122
  'transcribe_device_info': { size: 64, align: 8, offsets: { 'struct_size': 0, 'name': 8, 'description': 16, 'kind': 24, 'device_id': 32, 'memory_total': 40, 'memory_free': 48, 'device_type': 56 } },
117
123
  'transcribe_model_load_params': { size: 24, align: 8, offsets: { 'struct_size': 0, 'backend': 8, 'device': 16 } },
118
124
  'transcribe_session_params': { size: 24, align: 8, offsets: { 'struct_size': 0, 'n_threads': 8, 'kv_type': 12, 'n_ctx': 16 } },
119
- 'transcribe_run_params': { size: 72, align: 8, offsets: { 'struct_size': 0, 'task': 8, 'timestamps': 12, 'pnc': 16, 'itn': 20, 'diarize': 24, 'language': 32, 'target_language': 40, 'keep_special_tags': 48, 'family': 56, 'spec_k_drafts': 64 } },
125
+ 'transcribe_run_params': { size: 104, align: 8, offsets: { 'struct_size': 0, 'task': 8, 'timestamps': 12, 'pnc': 16, 'itn': 20, 'diarize': 24, 'language': 32, 'target_language': 40, 'keep_special_tags': 48, 'family': 56, 'spec_k_drafts': 64, 'vocabulary': 72, 'n_vocabulary': 80, 'prompt': 88, 'prefix': 96 } },
120
126
  'transcribe_capabilities': { size: 56, align: 8, offsets: { 'struct_size': 0, 'native_sample_rate': 8, 'n_languages': 12, 'languages': 16, 'max_timestamp_kind': 24, 'supports_language_detect': 28, 'supports_translate': 29, 'supports_streaming': 30, 'supports_spec_decode': 31, 'max_audio_ms': 32, 'n_translate_target_languages': 40, 'translate_target_languages': 48 } },
121
127
  'transcribe_session_limits': { size: 32, align: 8, offsets: { 'struct_size': 0, 'effective_n_ctx': 8, 'effective_max_audio_ms': 16, 'max_kv_bytes': 24 } },
122
128
  'transcribe_stream_params': { size: 24, align: 8, offsets: { 'struct_size': 0, 'family': 8, 'commit_policy': 16, 'stable_prefix_agreement_n': 20 } },
@@ -159,7 +165,7 @@ export function defineTypes(koffi) {
159
165
  T['transcribe_device_info'] = koffi.struct({ struct_size: 'uint64_t', name: 'char *', description: 'char *', kind: 'char *', device_id: 'char *', memory_total: 'uint64_t', memory_free: 'uint64_t', device_type: 'int' });
160
166
  T['transcribe_model_load_params'] = koffi.struct({ struct_size: 'uint64_t', backend: 'int', device: 'void *' });
161
167
  T['transcribe_session_params'] = koffi.struct({ struct_size: 'uint64_t', n_threads: 'int', kv_type: 'int', n_ctx: 'int32_t' });
162
- T['transcribe_run_params'] = koffi.struct({ struct_size: 'uint64_t', task: 'int', timestamps: 'int', pnc: 'int', itn: 'int', diarize: 'int', language: 'char *', target_language: 'char *', keep_special_tags: 'bool', family: 'void *', spec_k_drafts: 'int32_t' });
168
+ T['transcribe_run_params'] = koffi.struct({ struct_size: 'uint64_t', task: 'int', timestamps: 'int', pnc: 'int', itn: 'int', diarize: 'int', language: 'char *', target_language: 'char *', keep_special_tags: 'bool', family: 'void *', spec_k_drafts: 'int32_t', vocabulary: 'void *', n_vocabulary: 'int32_t', prompt: 'char *', prefix: 'char *' });
163
169
  T['transcribe_capabilities'] = koffi.struct({ struct_size: 'uint64_t', native_sample_rate: 'int32_t', n_languages: 'int', languages: 'void *', max_timestamp_kind: 'int', supports_language_detect: 'bool', supports_translate: 'bool', supports_streaming: 'bool', supports_spec_decode: 'bool', max_audio_ms: 'int64_t', n_translate_target_languages: 'int', translate_target_languages: 'void *' });
164
170
  T['transcribe_session_limits'] = koffi.struct({ struct_size: 'uint64_t', effective_n_ctx: 'int32_t', effective_max_audio_ms: 'int64_t', max_kv_bytes: 'int64_t' });
165
171
  T['transcribe_stream_params'] = koffi.struct({ struct_size: 'uint64_t', family: 'void *', commit_policy: 'int', stable_prefix_agreement_n: 'uint32_t' });
package/dist/errors.d.ts CHANGED
@@ -5,7 +5,7 @@ export declare class TranscribeError extends Error {
5
5
  readonly status: number;
6
6
  /** Set on per-utterance failures from a batch run. */
7
7
  utteranceIndex?: number;
8
- /** Any partial transcript recovered before the error (set on Aborted / OutputTruncated). */
8
+ /** Any partial transcript recovered before the error (set on Aborted / OutputTruncated / OutputRepetition). */
9
9
  partialResult?: TranscriptionResult;
10
10
  constructor(message: string, status?: number);
11
11
  }
@@ -43,6 +43,13 @@ export declare class Aborted extends TranscribeError {
43
43
  /** Raised when decode hits the context/generation cap; carries the partial in `partialResult`. */
44
44
  export declare class OutputTruncated extends TranscribeError {
45
45
  }
46
+ /**
47
+ * Raised when decode is stopped because the output began repeating itself; carries
48
+ * the partial (repeats dropped) in `partialResult`. Extends OutputTruncated, so a
49
+ * handler for incomplete transcripts catches both.
50
+ */
51
+ export declare class OutputRepetition extends OutputTruncated {
52
+ }
46
53
  /** Build (do not throw) the mapped exception for a status. */
47
54
  export declare function exceptionForStatus(status: number, statusString: string, context?: string): TranscribeError;
48
55
  /** Throw the mapped exception unless the status is OK. */
package/dist/errors.js CHANGED
@@ -5,7 +5,7 @@ export class TranscribeError extends Error {
5
5
  status;
6
6
  /** Set on per-utterance failures from a batch run. */
7
7
  utteranceIndex;
8
- /** Any partial transcript recovered before the error (set on Aborted / OutputTruncated). */
8
+ /** Any partial transcript recovered before the error (set on Aborted / OutputTruncated / OutputRepetition). */
9
9
  partialResult;
10
10
  constructor(message, status = g.TRANSCRIBE_OK) {
11
11
  super(message);
@@ -47,6 +47,13 @@ export class Aborted extends TranscribeError {
47
47
  /** Raised when decode hits the context/generation cap; carries the partial in `partialResult`. */
48
48
  export class OutputTruncated extends TranscribeError {
49
49
  }
50
+ /**
51
+ * Raised when decode is stopped because the output began repeating itself; carries
52
+ * the partial (repeats dropped) in `partialResult`. Extends OutputTruncated, so a
53
+ * handler for incomplete transcripts catches both.
54
+ */
55
+ export class OutputRepetition extends OutputTruncated {
56
+ }
50
57
  const STATUS_TO_EXC = {
51
58
  [g.TRANSCRIBE_ERR_INVALID_ARG]: InvalidArgument,
52
59
  [g.TRANSCRIBE_ERR_NOT_IMPLEMENTED]: NotImplementedByModel,
@@ -66,6 +73,7 @@ const STATUS_TO_EXC = {
66
73
  [g.TRANSCRIBE_ERR_UNSUPPORTED_ITN]: UnsupportedRequest,
67
74
  [g.TRANSCRIBE_ERR_INPUT_TOO_LONG]: InputTooLong,
68
75
  [g.TRANSCRIBE_ERR_OUTPUT_TRUNCATED]: OutputTruncated,
76
+ [g.TRANSCRIBE_ERR_OUTPUT_REPETITION]: OutputRepetition,
69
77
  };
70
78
  /** Build (do not throw) the mapped exception for a status. */
71
79
  export function exceptionForStatus(status, statusString, context = "") {
package/dist/ffi.js CHANGED
@@ -10,12 +10,9 @@
10
10
  import koffi from "koffi";
11
11
  import { defineTypes } from "./_generated.js";
12
12
  // Koffi defaults async FFI workers to a 128 KiB stack. That is too small for
13
- // ggml Vulkan model initialization on Windows (observed as an uncatchable
14
- // 0xC0000005 access violation on Intel Iris Xe). Keep calls asynchronous, but
15
- // raise the stack floor with headroom for other models and compiler changes.
16
- // Preserve a larger application-provided value because Koffi configuration is
17
- // process-global.
18
- const MIN_ASYNC_STACK_SIZE = 512 * 1024;
13
+ // ggml Vulkan model initialization on Windows for AMD and Intel GPU's.
14
+ // Raise it to 2MB.
15
+ const MIN_ASYNC_STACK_SIZE = 2 * 1024 * 1024;
19
16
  const koffiConfig = koffi.config();
20
17
  if ((koffiConfig.async_stack_size ?? 0) < MIN_ASYNC_STACK_SIZE) {
21
18
  koffi.config({ async_stack_size: MIN_ASYNC_STACK_SIZE });
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@
8
8
  import { native, setLogHandler, } from "./native.js";
9
9
  import { resolveLibrary } from "./loader.js";
10
10
  import * as g from "./_generated.js";
11
- import { Aborted, Busy, exceptionForStatus, InvalidArgument, ModelLoadError, NotImplementedByModel, OutputTruncated, TranscribeError, UnsupportedRequest, } from "./errors.js";
11
+ import { Aborted, Busy, exceptionForStatus, InvalidArgument, ModelLoadError, NotImplementedByModel, OutputRepetition, OutputTruncated, TranscribeError, UnsupportedRequest, } from "./errors.js";
12
12
  export * from "./types.js";
13
13
  export * from "./errors.js";
14
14
  export { setLogHandler };
@@ -30,6 +30,7 @@ const KV_TYPES = {
30
30
  const TASKS = {
31
31
  transcribe: g.TRANSCRIBE_TASK_TRANSCRIBE,
32
32
  translate: g.TRANSCRIBE_TASK_TRANSLATE,
33
+ instruct: g.TRANSCRIBE_TASK_INSTRUCT,
33
34
  };
34
35
  const TIMESTAMPS = {
35
36
  none: g.TRANSCRIBE_TIMESTAMPS_NONE,
@@ -62,6 +63,10 @@ const FEATURES = {
62
63
  pnc: g.TRANSCRIBE_FEATURE_PNC,
63
64
  itn: g.TRANSCRIBE_FEATURE_ITN,
64
65
  diarization: g.TRANSCRIBE_FEATURE_DIARIZATION,
66
+ vocabulary: g.TRANSCRIBE_FEATURE_VOCABULARY,
67
+ context_prompt: g.TRANSCRIBE_FEATURE_CONTEXT_PROMPT,
68
+ instruct: g.TRANSCRIBE_FEATURE_INSTRUCT,
69
+ transcript_prefix: g.TRANSCRIBE_FEATURE_TRANSCRIPT_PREFIX,
65
70
  };
66
71
  // ---- helpers ---------------------------------------------------------------
67
72
  function lookup(map, key, what) {
@@ -438,7 +443,7 @@ const FAMILY = {
438
443
  type: "transcribe_whisper_run_ext",
439
444
  init: "whisperRunExtInit",
440
445
  map: (o) => ({
441
- initial_prompt: o.initialPrompt,
446
+ initial_prompt: o.initialPrompt === undefined ? undefined : cstr(o.initialPrompt, "initialPrompt"),
442
447
  condition_on_prev_tokens: o.conditionOnPrevTokens,
443
448
  temperature: o.temperature,
444
449
  temperature_inc: o.temperatureInc,
@@ -525,6 +530,20 @@ function buildFamily(n, modelHandle, family, slot) {
525
530
  n.koffi.encode(buf, n.T[reg.type], ext);
526
531
  return buf;
527
532
  }
533
+ /** A string option as passed to C, which would silently cut it at a NUL. */
534
+ function cstr(value, name) {
535
+ if (value.includes("\0"))
536
+ throw new InvalidArgument(`${name} contains a NUL character`);
537
+ return value;
538
+ }
539
+ /** Free what #buildRunParams allocated; call once the native call returns. */
540
+ function freeRunParams(n, p) {
541
+ if (p.vocabulary) {
542
+ n.koffi.free(p.vocabulary);
543
+ p.vocabulary = null;
544
+ p.n_vocabulary = 0;
545
+ }
546
+ }
528
547
  function toStreamUpdate(u) {
529
548
  return {
530
549
  resultChanged: u.result_changed,
@@ -639,7 +658,8 @@ export class Session {
639
658
  cancel?.();
640
659
  }
641
660
  if (status === g.TRANSCRIBE_ERR_ABORTED ||
642
- status === g.TRANSCRIBE_ERR_OUTPUT_TRUNCATED) {
661
+ status === g.TRANSCRIBE_ERR_OUTPUT_TRUNCATED ||
662
+ status === g.TRANSCRIBE_ERR_OUTPUT_REPETITION) {
643
663
  const partial = {
644
664
  ...materialize(n, singleAccessors(n, h)),
645
665
  aborted: F.wasAborted(h),
@@ -647,7 +667,9 @@ export class Session {
647
667
  };
648
668
  const exc = status === g.TRANSCRIBE_ERR_ABORTED
649
669
  ? new Aborted(`run aborted`, status)
650
- : new OutputTruncated(`run output truncated`, status);
670
+ : status === g.TRANSCRIBE_ERR_OUTPUT_REPETITION
671
+ ? new OutputRepetition(`run stopped: output began repeating`, status)
672
+ : new OutputTruncated(`run output truncated`, status);
651
673
  exc.partialResult = partial;
652
674
  throw exc;
653
675
  }
@@ -657,7 +679,7 @@ export class Session {
657
679
  aborted: F.wasAborted(h),
658
680
  truncated: F.wasTruncated(h),
659
681
  };
660
- });
682
+ }).finally(() => freeRunParams(n, p));
661
683
  }
662
684
  #buildRunParams(opts) {
663
685
  const n = this.#n;
@@ -672,15 +694,33 @@ export class Session {
672
694
  p.itn = lookup(ITN, opts.itn ?? "default", "itn");
673
695
  p.diarize = lookup(DIARIZE, opts.diarize ?? "default", "diarize");
674
696
  if (opts.language !== undefined)
675
- p.language = opts.language;
697
+ p.language = cstr(opts.language, "language");
676
698
  if (opts.targetLanguage !== undefined)
677
- p.target_language = opts.targetLanguage;
699
+ p.target_language = cstr(opts.targetLanguage, "targetLanguage");
678
700
  if (opts.keepSpecialTags !== undefined)
679
701
  p.keep_special_tags = opts.keepSpecialTags;
680
702
  if (opts.specKDrafts !== undefined)
681
703
  p.spec_k_drafts = opts.specKDrafts;
682
704
  if (opts.family)
683
705
  p.family = buildFamily(n, this.#model.handle, opts.family, "run");
706
+ if (opts.vocabulary !== undefined) {
707
+ const terms = opts.vocabulary;
708
+ if (!Array.isArray(terms) || !terms.every((t) => typeof t === "string"))
709
+ throw new InvalidArgument("vocabulary must be an array of strings");
710
+ if (terms.length > 0) {
711
+ // Freed by freeRunParams after the call; the library copies the terms.
712
+ terms.forEach((t) => cstr(t, "vocabulary"));
713
+ const type = n.koffi.array("char *", terms.length);
714
+ const arr = n.koffi.alloc(type, 1);
715
+ n.koffi.encode(arr, type, terms);
716
+ p.vocabulary = arr;
717
+ p.n_vocabulary = terms.length;
718
+ }
719
+ }
720
+ if (opts.prompt !== undefined)
721
+ p.prompt = cstr(opts.prompt, "prompt");
722
+ if (opts.prefix !== undefined)
723
+ p.prefix = cstr(opts.prefix, "prefix");
684
724
  return p;
685
725
  }
686
726
  /**
@@ -734,18 +774,20 @@ export class Session {
734
774
  const error = exceptionForStatus(st, F.statusString(st), `utterance ${i}`);
735
775
  error.utteranceIndex = i;
736
776
  if (st === g.TRANSCRIBE_ERR_ABORTED ||
737
- st === g.TRANSCRIBE_ERR_OUTPUT_TRUNCATED) {
777
+ st === g.TRANSCRIBE_ERR_OUTPUT_TRUNCATED ||
778
+ st === g.TRANSCRIBE_ERR_OUTPUT_REPETITION) {
738
779
  error.partialResult = {
739
780
  ...materialize(n, batchAccessors(n, h, i)),
740
781
  aborted: st === g.TRANSCRIBE_ERR_ABORTED,
741
- truncated: st === g.TRANSCRIBE_ERR_OUTPUT_TRUNCATED,
782
+ truncated: st === g.TRANSCRIBE_ERR_OUTPUT_TRUNCATED ||
783
+ st === g.TRANSCRIBE_ERR_OUTPUT_REPETITION,
742
784
  };
743
785
  }
744
786
  out.push({ ok: false, error });
745
787
  }
746
788
  }
747
789
  return out;
748
- });
790
+ }).finally(() => freeRunParams(n, p));
749
791
  }
750
792
  /** Begin a streaming session. The returned Stream owns the begin params. */
751
793
  async stream(opts = {}) {
@@ -762,6 +804,8 @@ export class Session {
762
804
  diarize: opts.diarize,
763
805
  keepSpecialTags: opts.keepSpecialTags,
764
806
  specKDrafts: -1,
807
+ vocabulary: opts.vocabulary,
808
+ prompt: opts.prompt,
765
809
  });
766
810
  const sp = {};
767
811
  F.streamParamsInit(sp);
@@ -788,7 +832,7 @@ export class Session {
788
832
  throw new TranscribeError("session control is missing");
789
833
  control.replaceCurrentStream(stream);
790
834
  return stream;
791
- });
835
+ }).finally(() => freeRunParams(n, rp)); // begin copied the prompting strings
792
836
  }
793
837
  /**
794
838
  * Wire an AbortSignal to a native abort callback for one run. The callback is
package/dist/types.d.ts CHANGED
@@ -2,12 +2,14 @@
2
2
  import type { TranscribeError } from "./errors.js";
3
3
  export type Backend = "auto" | "cpu" | "cpu_accel" | "cuda" | "rocm" | "vulkan" | "metal";
4
4
  export type KvType = "auto" | "f32" | "f16";
5
- export type Task = "transcribe" | "translate";
5
+ /** "instruct": `prompt` replaces the task instruction and the output is free
6
+ * text ("instruct" feature; offline only). */
7
+ export type Task = "transcribe" | "translate" | "instruct";
6
8
  export type TimestampKind = "none" | "auto" | "segment" | "word" | "token";
7
9
  export type Pnc = "default" | "off" | "on";
8
10
  export type Itn = "default" | "off" | "on";
9
11
  export type Diarize = "default" | "off" | "on";
10
- export type Feature = "initial_prompt" | "temperature_fallback" | "long_form" | "cancellation" | "pnc" | "itn" | "diarization";
12
+ export type Feature = "initial_prompt" | "temperature_fallback" | "long_form" | "cancellation" | "pnc" | "itn" | "diarization" | "vocabulary" | "context_prompt" | "instruct" | "transcript_prefix";
11
13
  /** Mono float32 PCM at the model's native sample rate (16 kHz for v1). */
12
14
  export type PcmLike = Float32Array | number[] | ArrayBuffer | Buffer;
13
15
  export interface Segment {
@@ -144,6 +146,16 @@ export interface TranscribeOptions {
144
146
  signal?: AbortSignal;
145
147
  /** A run-slot family extension (e.g. whisper). */
146
148
  family?: FamilyExtension;
149
+ /** Custom terms in priority order, formatted per family ("vocabulary"
150
+ * feature; ignored with a warning elsewhere). */
151
+ vocabulary?: readonly string[];
152
+ /** Context text under transcribe/translate ("context_prompt" feature); the
153
+ * required instruction under task "instruct". */
154
+ prompt?: string;
155
+ /** Transcript text the model continues from ("transcript_prefix" feature;
156
+ * an error elsewhere, and in runBatch). `text` holds only the continuation;
157
+ * `rawText` leads with the prefix. */
158
+ prefix?: string;
147
159
  }
148
160
  /** One result of a batch run: success carries the transcript, failure the error.
149
161
  * On failure, `error.utteranceIndex` is set, and `error.partialResult` carries any
@@ -187,6 +199,10 @@ export interface StreamOptions {
187
199
  keepSpecialTags?: boolean;
188
200
  commitPolicy?: CommitPolicy;
189
201
  stablePrefixAgreementN?: number;
202
+ /** Custom terms in priority order (see TranscribeOptions.vocabulary). */
203
+ vocabulary?: readonly string[];
204
+ /** Context text (see TranscribeOptions.prompt). */
205
+ prompt?: string;
190
206
  /** A stream-slot family extension (moonshine, parakeet, voxtral). */
191
207
  family?: FamilyExtension;
192
208
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "transcribe-cpp",
3
- "version": "0.2.3",
3
+ "version": "0.3.0",
4
4
  "description": "TypeScript/Node.js bindings for transcribe.cpp — a C/C++ speech-to-text library built on ggml",
5
5
  "type": "module",
6
6
  "exports": {
@@ -51,11 +51,11 @@
51
51
  "koffi": "^3.0.2"
52
52
  },
53
53
  "optionalDependencies": {
54
- "@transcribe-cpp/darwin-arm64-metal": "0.2.3",
55
- "@transcribe-cpp/darwin-x64-cpu": "0.2.3",
56
- "@transcribe-cpp/linux-x64-cpu-vulkan": "0.2.3",
57
- "@transcribe-cpp/linux-arm64-cpu-vulkan": "0.2.3",
58
- "@transcribe-cpp/win32-x64-cpu-vulkan": "0.2.3"
54
+ "@transcribe-cpp/darwin-arm64-metal": "0.3.0",
55
+ "@transcribe-cpp/darwin-x64-cpu": "0.3.0",
56
+ "@transcribe-cpp/linux-x64-cpu-vulkan": "0.3.0",
57
+ "@transcribe-cpp/linux-arm64-cpu-vulkan": "0.3.0",
58
+ "@transcribe-cpp/win32-x64-cpu-vulkan": "0.3.0"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@types/node": "^22.0.0",