@gjsify/speech-recognition 0.64.51 → 0.64.53

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
@@ -38,6 +38,19 @@ recognition.stop(); // delivers the pending utterance, then `end`
38
38
 
39
39
  Without `/register`, import the classes: `import { SpeechRecognition } from '@gjsify/speech-recognition'`.
40
40
 
41
+ ## Transcribing a finished recording
42
+
43
+ `transcribe()` decodes a whole recording at once on an offline model (NVIDIA Parakeet TDT 0.6B v3, int8, CC-BY-4.0, 25 languages with language detection). It takes 16 kHz mono Float32 PCM, a file path or a `Gio.File`. Files go through [`@gjsify/media-capture`](../media-capture#readme), so anything GStreamer's `decodebin` reads works (Ogg/Opus voice notes, M4A, MP3, WAV). See [ADR 0150](../../../docs/adr/0150-transcribe-decodes-a-finished-recording-on-an-offline-engine.md).
44
+
45
+ ```typescript
46
+ import { SpeechRecognition, transcribe } from '@gjsify/speech-recognition';
47
+
48
+ await SpeechRecognition.install({ langs: ['de'], quality: 'conversation', kind: 'offline' }); // ~623 MiB, once
49
+ const { text, language, engine } = await transcribe('/path/voice-note.opus', { signal });
50
+ ```
51
+
52
+ Options: `lang` (hint), `phrases`, `signal`, `model` (an offline id). `phrases` are not applied yet: the sherpa-native C shim passes no BPE vocabulary, which NeMo hotwords need, so the engine reports `hotwords: false`. Another backend plugs in as an `OfflineEngine`; `createFakeOfflineEngine()` stands in for tests. The real-engine spec skips without the prebuild or the cached model.
53
+
41
54
  ## Surface
42
55
 
43
56
  | Member | Behavior here |
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";function createFakeOfflineEngine(e={}){let t={text:``,language:null},n=null,r=[],i=[],a={opened:!1,closed:!1};return{name:e.name??`fake`,hotwords:e.hotwords??!1,answer(e){t={text:e.text??``,language:e.language??null}},failWith(e){n=e},recordings:r,calls:i,get opened(){return a.opened},get closed(){return a.closed},open(){a.opened=!0},transcribe(e,a){if(r.push(e),i.push(a),n!==null)throw n;return{...t}},close(){a.closed=!0}}}export{createFakeOfflineEngine};
package/lib/esm/index.js CHANGED
@@ -1 +1 @@
1
- import{createSherpaEngine as e,describeRecognitionBackend as t,hasRecognitionBackend as n}from"./backend.js";import{SpeechRecognitionAlternative as r,SpeechRecognitionPhrase as i,SpeechRecognitionResult as a,SpeechRecognitionResultList as o}from"./results.js";import{SpeechRecognitionErrorEvent as s,SpeechRecognitionEvent as c}from"./events.js";import{createFakeRecognizerEngine as l}from"./fake-engine.js";import{DEFAULT_RECOGNITION_MODEL as u,RECOGNITION_MODELS as d,findRecognitionModel as f,modelFor as p}from"./model-manifest.js";import{available as m,install as h,isModelCached as g,modelCacheDir as _,uninstall as v}from"./models.js";import{SpeechRecognition as y}from"./recognition.js";export{u as DEFAULT_RECOGNITION_MODEL,d as RECOGNITION_MODELS,y as SpeechRecognition,r as SpeechRecognitionAlternative,s as SpeechRecognitionErrorEvent,c as SpeechRecognitionEvent,i as SpeechRecognitionPhrase,a as SpeechRecognitionResult,o as SpeechRecognitionResultList,m as available,l as createFakeRecognizerEngine,e as createSherpaEngine,t as describeRecognitionBackend,f as findRecognitionModel,n as hasRecognitionBackend,h as install,g as isModelCached,_ as modelCacheDir,p as modelFor,v as uninstall};
1
+ import{createSherpaEngine as e,describeRecognitionBackend as t,hasRecognitionBackend as n}from"./backend.js";import{SpeechRecognitionAlternative as r,SpeechRecognitionPhrase as i,SpeechRecognitionResult as a,SpeechRecognitionResultList as o}from"./results.js";import{SpeechRecognitionErrorEvent as s,SpeechRecognitionEvent as c}from"./events.js";import{createFakeRecognizerEngine as l}from"./fake-engine.js";import{createFakeOfflineEngine as u}from"./fake-offline-engine.js";import{DEFAULT_RECOGNITION_MODEL as d,DEFAULT_TRANSCRIBE_MODEL as f,RECOGNITION_MODELS as p,findRecognitionModel as m,modelFor as h}from"./model-manifest.js";import{available as g,install as _,isModelCached as v,modelCacheDir as y,uninstall as b}from"./models.js";import{SpeechRecognition as x}from"./recognition.js";import{createSherpaOfflineEngine as S}from"./offline-engine.js";import{TRANSCRIBE_SAMPLE_RATE as C,transcribe as w}from"./transcribe.js";export{d as DEFAULT_RECOGNITION_MODEL,f as DEFAULT_TRANSCRIBE_MODEL,p as RECOGNITION_MODELS,x as SpeechRecognition,r as SpeechRecognitionAlternative,s as SpeechRecognitionErrorEvent,c as SpeechRecognitionEvent,i as SpeechRecognitionPhrase,a as SpeechRecognitionResult,o as SpeechRecognitionResultList,C as TRANSCRIBE_SAMPLE_RATE,g as available,u as createFakeOfflineEngine,l as createFakeRecognizerEngine,e as createSherpaEngine,S as createSherpaOfflineEngine,t as describeRecognitionBackend,m as findRecognitionModel,n as hasRecognitionBackend,_ as install,v as isModelCached,y as modelCacheDir,h as modelFor,w as transcribe,b as uninstall};
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";const e=[`command`,`dictation`,`conversation`],t=`zipformer-de-kroko`,n=`https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-de-kroko-2025-08-06/resolve/main`,r=[{id:`zipformer-de-kroko`,files:[{file:`encoder.onnx`,url:`${n}/encoder.onnx`,bytes:70091557,sha256:`6e83993d6967ec7a3498b055b7e85ace85b5d64d1b1e8773cb29a43a11f5edb5`},{file:`decoder.onnx`,url:`${n}/decoder.onnx`,bytes:617489,sha256:`94a29592b403c53fa2231b478637da1ab4abcef7f5e46e432098416a4a3ed562`},{file:`joiner.onnx`,url:`${n}/joiner.onnx`,bytes:336817,sha256:`28356bff070aea51ab1d725a3278e81d19f9300f860d3248a7014292264df15a`},{file:`tokens.txt`,url:`${n}/tokens.txt`,bytes:5606,sha256:`86e8370994ff2c01149ba8c4f8709aa93cdc18914b27a717e291e96faf39a6eb`}],license:`Kroko community model (advertised CC-BY-SA; the mirror declares none)`,redistributable:!1,description:`Kroko streaming zipformer, German (68 MB) — interim results on CPU, ~32 ms after end of speech.`,langs:[`de`],quality:`dictation`,sampleRate:16e3,hotwords:!1,encoder:`encoder.onnx`,decoder:`decoder.onnx`,joiner:`joiner.onnx`,tokens:`tokens.txt`}];function findRecognitionModel(e=t){return r.find(t=>t.id===e)}function modelFor(t,n=`command`){let i=t.split(`-`)[0].toLowerCase(),a=e.indexOf(n);return r.find(t=>t.langs.includes(i)&&e.indexOf(t.quality)>=a)}export{t as DEFAULT_RECOGNITION_MODEL,e as QUALITY_ORDER,r as RECOGNITION_MODELS,findRecognitionModel,modelFor};
1
+ import"./_virtual/_rolldown/runtime.js";const e=[`command`,`dictation`,`conversation`],t=`zipformer-de-kroko`,n=`parakeet-tdt-0.6b-v3-int8`,r=`https://huggingface.co/csukuangfj/sherpa-onnx-nemo-parakeet-tdt-0.6b-v3-int8/resolve/main`,i=`https://huggingface.co/csukuangfj/sherpa-onnx-streaming-zipformer-de-kroko-2025-08-06/resolve/main`,a=[{id:`zipformer-de-kroko`,kind:`streaming`,files:[{file:`encoder.onnx`,url:`${i}/encoder.onnx`,bytes:70091557,sha256:`6e83993d6967ec7a3498b055b7e85ace85b5d64d1b1e8773cb29a43a11f5edb5`},{file:`decoder.onnx`,url:`${i}/decoder.onnx`,bytes:617489,sha256:`94a29592b403c53fa2231b478637da1ab4abcef7f5e46e432098416a4a3ed562`},{file:`joiner.onnx`,url:`${i}/joiner.onnx`,bytes:336817,sha256:`28356bff070aea51ab1d725a3278e81d19f9300f860d3248a7014292264df15a`},{file:`tokens.txt`,url:`${i}/tokens.txt`,bytes:5606,sha256:`86e8370994ff2c01149ba8c4f8709aa93cdc18914b27a717e291e96faf39a6eb`}],license:`Kroko community model (advertised CC-BY-SA; the mirror declares none)`,redistributable:!1,description:`Kroko streaming zipformer, German (68 MB) — interim results on CPU, ~32 ms after end of speech.`,langs:[`de`],quality:`dictation`,sampleRate:16e3,hotwords:!1,encoder:`encoder.onnx`,decoder:`decoder.onnx`,joiner:`joiner.onnx`,tokens:`tokens.txt`},{id:n,kind:`offline`,modelType:`nemo_transducer`,files:[{file:`encoder.int8.onnx`,url:`${r}/encoder.int8.onnx`,bytes:652282294,sha256:`1afbe69c1ffdabee94755f42e4daf1d93549131a3da11356bda84fcef0f2c479`},{file:`decoder.int8.onnx`,url:`${r}/decoder.int8.onnx`,bytes:11845274,sha256:`0222a86147299d4dee90edf95b6d13827edb42ad8b7c9cf0b2582f030937c0b5`},{file:`joiner.int8.onnx`,url:`${r}/joiner.int8.onnx`,bytes:6355277,sha256:`cbd02f3696e9944970111fb439d9c3fd365a80374565f13f2b9c7007d253fc98`},{file:`tokens.txt`,url:`${r}/tokens.txt`,bytes:93939,sha256:`d58544679ea4bc6ac563d1f545eb7d474bd6cfa467f0a6e2c1dc1c7d37e3c35d`}],license:`CC-BY-4.0`,redistributable:!0,description:`NVIDIA Parakeet TDT 0.6B v3, int8 (623 MiB) — offline, 25 European languages with automatic language detection.`,langs:[`bg`,`hr`,`cs`,`da`,`nl`,`en`,`et`,`fi`,`fr`,`de`,`el`,`hu`,`it`,`lv`,`lt`,`mt`,`pl`,`pt`,`ro`,`sk`,`sl`,`es`,`sv`,`ru`,`uk`],quality:`conversation`,sampleRate:16e3,hotwords:!1,encoder:`encoder.int8.onnx`,decoder:`decoder.int8.onnx`,joiner:`joiner.int8.onnx`,tokens:`tokens.txt`}];function findRecognitionModel(e=t){return a.find(t=>t.id===e)}function modelFor(t,n=`command`,r=`streaming`){let i=t.split(`-`)[0].toLowerCase(),o=e.indexOf(n);return a.find(t=>t.kind===r&&t.langs.includes(i)&&e.indexOf(t.quality)>=o)}export{t as DEFAULT_RECOGNITION_MODEL,n as DEFAULT_TRANSCRIBE_MODEL,e as QUALITY_ORDER,a as RECOGNITION_MODELS,findRecognitionModel,modelFor};
package/lib/esm/models.js CHANGED
@@ -1 +1 @@
1
- import"./_virtual/_rolldown/runtime.js";import{hasRecognitionBackend as e}from"./backend.js";import{syntaxError as t}from"./results.js";import{DEFAULT_RECOGNITION_MODEL as n,RECOGNITION_MODELS as r,modelFor as i}from"./model-manifest.js";import{ModelStore as a}from"@gjsify/model-store";const o=new a({capability:`speech`,models:r,defaultModel:n});function modelCacheDir(){return o.cacheDir}function resolveRecognitionModel(e){let t=o.locate(e.id);if(t===void 0)throw Error(`Recognition model '${e.id}' is not cached (${o.cachePath(e.id)}) — await SpeechRecognition.install() first.`);return t.files}function isModelCached(e){return o.locate(e.id)!==void 0}function validateLanguageTag(e){try{if(typeof e!=`string`||e===``)throw RangeError(`empty`);new Intl.Locale(e)}catch{throw t(`'${e}' is not a valid BCP 47 language tag`)}}const s={available:0,downloading:1,downloadable:2,unavailable:3};function statusFor(t,n){let r=i(t,n);return r===void 0||!e()?`unavailable`:o.availability(r.id)}async function available(e){let t=e?.langs;if(!Array.isArray(t))throw TypeError(`available(): options.langs must be an array of BCP 47 tags`);for(let e of t)validateLanguageTag(e);if(t.length===0)return`unavailable`;let n=e.quality??`command`;return t.map(e=>statusFor(e,n)).reduce((e,t)=>s[t]>s[e]?t:e,`available`)}async function install(t){let n=t?.langs;if(!Array.isArray(n))throw TypeError(`install(): options.langs must be an array of BCP 47 tags`);for(let e of n)validateLanguageTag(e);if(n.length===0)return!1;let r=t.quality??`command`,a=n.map(e=>i(e,r));if(a.some(e=>e===void 0)||!e())return!1;let{onProgress:s}=t;try{for(let e of new Set(a))await o.install(e.id,{signal:t.signal,fetch:t.fetchImpl,monitor:s===void 0?void 0:t=>t.addEventListener(`downloadprogress`,t=>{let{receivedBytes:n,totalBytes:r}=t;s({modelId:e.id,received:n,total:r})})});return!0}catch{return!1}}function uninstall(e=n){o.require(e);try{return o.uninstall(e)}catch{return!1}}export{available,install,isModelCached,modelCacheDir,resolveRecognitionModel,uninstall,validateLanguageTag};
1
+ import"./_virtual/_rolldown/runtime.js";import{hasRecognitionBackend as e}from"./backend.js";import{syntaxError as t}from"./results.js";import{DEFAULT_RECOGNITION_MODEL as n,RECOGNITION_MODELS as r,modelFor as i}from"./model-manifest.js";import{ModelStore as a}from"@gjsify/model-store";const o=new a({capability:`speech`,models:r,defaultModel:n});function modelCacheDir(){return o.cacheDir}function resolveRecognitionModel(e){let t=o.locate(e.id);if(t===void 0)throw Error(`Recognition model '${e.id}' is not cached (${o.cachePath(e.id)}) — await SpeechRecognition.install() first.`);return t.files}function isModelCached(e){return o.locate(e.id)!==void 0}function validateLanguageTag(e){try{if(typeof e!=`string`||e===``)throw RangeError(`empty`);new Intl.Locale(e)}catch{throw t(`'${e}' is not a valid BCP 47 language tag`)}}const s={available:0,downloading:1,downloadable:2,unavailable:3};function statusFor(t,n,r){let a=i(t,n,r);return a===void 0||!e()?`unavailable`:o.availability(a.id)}async function available(e){let t=e?.langs;if(!Array.isArray(t))throw TypeError(`available(): options.langs must be an array of BCP 47 tags`);for(let e of t)validateLanguageTag(e);if(t.length===0)return`unavailable`;let n=e.quality??`command`;return t.map(t=>statusFor(t,n,e.kind??`streaming`)).reduce((e,t)=>s[t]>s[e]?t:e,`available`)}async function install(t){let n=t?.langs;if(!Array.isArray(n))throw TypeError(`install(): options.langs must be an array of BCP 47 tags`);for(let e of n)validateLanguageTag(e);if(n.length===0)return!1;let r=t.quality??`command`,a=n.map(e=>i(e,r,t.kind??`streaming`));if(a.some(e=>e===void 0)||!e())return!1;let{onProgress:s}=t;try{for(let e of new Set(a))await o.install(e.id,{signal:t.signal,fetch:t.fetchImpl,monitor:s===void 0?void 0:t=>t.addEventListener(`downloadprogress`,t=>{let{receivedBytes:n,totalBytes:r}=t;s({modelId:e.id,received:n,total:r})})});return!0}catch{return!1}}function uninstall(e=n){o.require(e);try{return o.uninstall(e)}catch{return!1}}export{available,install,isModelCached,modelCacheDir,resolveRecognitionModel,uninstall,validateLanguageTag};
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";import{describeRecognitionBackend as e}from"./backend.js";import{loadNativeSherpa as t}from"@gjsify/sherpa-native";function createSherpaOfflineEngine(n){let r=t();if(r===null)throw Error(e());let i=new r.OfflineRecognizer({encoder:n.encoder,decoder:n.decoder,joiner:n.joiner,tokens:n.tokens,model_type:n.modelType??null,sample_rate:n.sampleRate,num_threads:n.numThreads??2});return{name:n.name,hotwords:!1,open(){i.open()},transcribe(e){let t=i.create_stream(null);try{t.accept(n.sampleRate,e),t.decode();let r=t.get_text().trim(),i=null;try{let e=JSON.parse(t.get_json()).lang;typeof e==`string`&&e!==``&&(i=e)}catch{}return{text:r,language:i}}finally{t.close()}},close(){i.close()}}}export{createSherpaOfflineEngine};
@@ -0,0 +1 @@
1
+ import"./_virtual/_rolldown/runtime.js";import{hasRecognitionBackend as e}from"./backend.js";import{namedError as t}from"./results.js";import{findRecognitionModel as n}from"./model-manifest.js";import{resolveRecognitionModel as r}from"./models.js";import{createSherpaOfflineEngine as i}from"./offline-engine.js";import{openPcmSource as a}from"@gjsify/media-capture";const o=16e3;function throwIfAborted(e){if(e?.aborted)throw t(`transcribe() was aborted`,`AbortError`)}async function readFile(e,t){let n=a({file:e,sampleRate:o,format:`F32LE`}),r=[],i=0;try{for(;;){throwIfAborted(t);let e=await n.read();if(e===null)break;let a=new Float32Array(e.byteLength>>2);new Uint8Array(a.buffer).set(e.subarray(0,a.length*4)),r.push(a),i+=a.length}}finally{n.stop()}let s=new Float32Array(i),c=0;for(let e of r)s.set(e,c),c+=e.length;return s}async function samplesOf(e,t){if(e instanceof Float32Array)return e;if(typeof e==`string`)return readFile(e,t);if(typeof e==`object`&&e&&typeof e.get_path==`function`){let n=e.get_path();if(n===null)throw TypeError(`transcribe(): the Gio.File has no local path`);return readFile(n,t)}throw TypeError(`transcribe(): source must be a Float32Array, a file path or a Gio.File`)}async function transcribe(a,o={}){let s=n(o.model??`parakeet-tdt-0.6b-v3-int8`);if(s===void 0)throw t(`Unknown recognition model '${o.model}'`,`NotFoundError`);if(s.kind!==`offline`)throw TypeError(`transcribe(): model '${s.id}' is a streaming model; pick an offline one`);throwIfAborted(o.signal);let c;if(o.engine!==void 0)c=o.engine(s);else{if(!e())throw t(`transcribe(): no native recognition engine on this host`,`NotSupportedError`);let n;try{n=r(s)}catch(e){throw t(e instanceof Error?e.message:String(e),`NotFoundError`)}c=i({name:`sherpa-onnx/${s.id}`,encoder:n[s.encoder],decoder:n[s.decoder],joiner:n[s.joiner],tokens:n[s.tokens],modelType:s.modelType,sampleRate:s.sampleRate})}let l=await samplesOf(a,o.signal);throwIfAborted(o.signal);let u=c.hotwords&&o.phrases!==void 0&&o.phrases.length>0?o.phrases.map(e=>e.phrase):void 0;c.open();try{let e=c.transcribe(l,{hotwords:u});return{text:e.text,language:e.language,engine:c.name}}finally{c.close()}}export{o as TRANSCRIBE_SAMPLE_RATE,transcribe};
@@ -0,0 +1,17 @@
1
+ import type { OfflineDecodeOptions, OfflineEngine, OfflineResult } from './offline-engine.js';
2
+ export interface FakeOfflineEngine extends OfflineEngine {
3
+ /** What the next `transcribe()` answers. */
4
+ answer(result: Partial<OfflineResult>): void;
5
+ /** Make the next `transcribe()` throw. */
6
+ failWith(error: Error): void;
7
+ /** Every recording it was given, in order. */
8
+ readonly recordings: readonly Float32Array[];
9
+ /** The options of every call, in order. */
10
+ readonly calls: readonly (OfflineDecodeOptions | undefined)[];
11
+ readonly opened: boolean;
12
+ readonly closed: boolean;
13
+ }
14
+ export declare function createFakeOfflineEngine(options?: {
15
+ hotwords?: boolean;
16
+ name?: string;
17
+ }): FakeOfflineEngine;
@@ -11,3 +11,11 @@ export { createSherpaEngine, describeRecognitionBackend, hasRecognitionBackend }
11
11
  export type { RecognizerDetail, RecognizerEngine, RecognizerFrame, SherpaEngineConfig } from './backend.js';
12
12
  export { createFakeRecognizerEngine } from './fake-engine.js';
13
13
  export type { FakeEngineStep, FakeRecognizerEngine } from './fake-engine.js';
14
+ export { DEFAULT_TRANSCRIBE_MODEL } from './model-manifest.js';
15
+ export type { RecognitionModelKind } from './model-manifest.js';
16
+ export { createSherpaOfflineEngine } from './offline-engine.js';
17
+ export type { OfflineDecodeOptions, OfflineEngine, OfflineResult, SherpaOfflineEngineConfig, } from './offline-engine.js';
18
+ export { createFakeOfflineEngine } from './fake-offline-engine.js';
19
+ export type { FakeOfflineEngine } from './fake-offline-engine.js';
20
+ export { TRANSCRIBE_SAMPLE_RATE, transcribe } from './transcribe.js';
21
+ export type { TranscribeFile, TranscribeOptions, TranscribeSource, Transcription } from './transcribe.js';
@@ -2,8 +2,14 @@ import type { ModelEntry } from '@gjsify/model-store';
2
2
  /** The Web Speech `SpeechRecognitionQuality`, ordered. */
3
3
  export type RecognitionQuality = 'command' | 'dictation' | 'conversation';
4
4
  export declare const QUALITY_ORDER: readonly RecognitionQuality[];
5
- /** One fetchable streaming transducer. */
5
+ /** `streaming` feeds `SpeechRecognition`; `offline` decodes a finished recording in `transcribe()`. */
6
+ export type RecognitionModelKind = 'streaming' | 'offline';
7
+ /** One fetchable transducer, streaming or offline. */
6
8
  export interface RecognitionModelEntry extends ModelEntry {
9
+ /** Which API loads it. A streaming session never picks an offline model, and the reverse. */
10
+ readonly kind: RecognitionModelKind;
11
+ /** sherpa-onnx `model_type` the offline recognizer needs (e.g. `nemo_transducer`). */
12
+ readonly modelType?: string;
7
13
  readonly description: string;
8
14
  /** Primary language subtags this model recognizes (`de` covers `de-DE`, `de-AT`, …). */
9
15
  readonly langs: readonly string[];
@@ -19,7 +25,9 @@ export interface RecognitionModelEntry extends ModelEntry {
19
25
  readonly tokens: string;
20
26
  }
21
27
  export declare const DEFAULT_RECOGNITION_MODEL = "zipformer-de-kroko";
28
+ /** The default `transcribe()` model: multilingual, detects the language itself. */
29
+ export declare const DEFAULT_TRANSCRIBE_MODEL = "parakeet-tdt-0.6b-v3-int8";
22
30
  export declare const RECOGNITION_MODELS: readonly RecognitionModelEntry[];
23
31
  export declare function findRecognitionModel(id?: string): RecognitionModelEntry | undefined;
24
- /** The first model that recognizes `lang` (a BCP 47 tag) at `quality` or better. */
25
- export declare function modelFor(lang: string, quality?: RecognitionQuality): RecognitionModelEntry | undefined;
32
+ /** The first model of `kind` that recognizes `lang` (a BCP 47 tag) at `quality` or better. */
33
+ export declare function modelFor(lang: string, quality?: RecognitionQuality, kind?: RecognitionModelKind): RecognitionModelEntry | undefined;
@@ -1,5 +1,5 @@
1
1
  import { type FetchLike, type ModelAvailability } from '@gjsify/model-store';
2
- import { type RecognitionModelEntry, type RecognitionQuality } from './model-manifest.js';
2
+ import { type RecognitionModelEntry, type RecognitionModelKind, type RecognitionQuality } from './model-manifest.js';
3
3
  export type SpeechRecognitionAvailability = ModelAvailability;
4
4
  export interface SpeechRecognitionOptions {
5
5
  langs: string[];
@@ -7,10 +7,14 @@ export interface SpeechRecognitionOptions {
7
7
  processLocally?: boolean;
8
8
  /** Spec default `command`. A model that cannot honestly serve it is `unavailable`. */
9
9
  quality?: RecognitionQuality;
10
+ /** `streaming` (default) is the model `SpeechRecognition` runs; `offline` is the one `transcribe()` runs. */
11
+ kind?: RecognitionModelKind;
10
12
  }
11
13
  export interface SpeechRecognitionInstallOptions {
12
14
  langs: string[];
13
15
  quality?: RecognitionQuality;
16
+ /** See {@link SpeechRecognitionOptions.kind}. */
17
+ kind?: RecognitionModelKind;
14
18
  /** Called at least once, with `received === total` on success. */
15
19
  onProgress?: (progress: {
16
20
  modelId: string;
@@ -0,0 +1,35 @@
1
+ /** What the engine heard in one recording. */
2
+ export interface OfflineResult {
3
+ text: string;
4
+ /** BCP 47 primary subtag the engine detected, or `null` when it does not say. */
5
+ language: string | null;
6
+ }
7
+ export interface OfflineDecodeOptions {
8
+ /** Contextual-biasing phrases. Ignored by an engine whose {@link OfflineEngine.hotwords} is false. */
9
+ hotwords?: readonly string[];
10
+ }
11
+ export interface OfflineEngine {
12
+ /** Names the backend and model in `Transcription.engine`, e.g. `sherpa-onnx/parakeet-tdt-0.6b-v3-int8`. */
13
+ readonly name: string;
14
+ /** Whether {@link OfflineDecodeOptions.hotwords} changes the result. */
15
+ readonly hotwords: boolean;
16
+ /** Load the model. Throws when it cannot be opened. */
17
+ open(): void;
18
+ /** Decode a whole recording: mono Float32 at 16 kHz. */
19
+ transcribe(samples: Float32Array, options?: OfflineDecodeOptions): OfflineResult;
20
+ /** Release the model. Idempotent. */
21
+ close(): void;
22
+ }
23
+ export interface SherpaOfflineEngineConfig {
24
+ name: string;
25
+ encoder: string;
26
+ decoder: string;
27
+ joiner: string;
28
+ tokens: string;
29
+ /** sherpa-onnx `model_type`, e.g. `nemo_transducer`. */
30
+ modelType?: string;
31
+ sampleRate: number;
32
+ numThreads?: number;
33
+ }
34
+ /** An {@link OfflineEngine} over `GjsifySherpa.OfflineRecognizer`. */
35
+ export declare function createSherpaOfflineEngine(config: SherpaOfflineEngineConfig): OfflineEngine;
@@ -0,0 +1,2 @@
1
+ declare const _default: () => Promise<void>;
2
+ export default _default;
@@ -0,0 +1,36 @@
1
+ import { type RecognitionModelEntry } from './model-manifest.js';
2
+ import { type OfflineEngine } from './offline-engine.js';
3
+ import { type SpeechRecognitionPhrase } from './results.js';
4
+ /** The rate every engine here takes; PCM input must already be at it. */
5
+ export declare const TRANSCRIBE_SAMPLE_RATE = 16000;
6
+ /** A `Gio.File`, as far as `transcribe()` needs one; typed structurally so callers need no Gio import. */
7
+ export interface TranscribeFile {
8
+ get_path(): string | null;
9
+ }
10
+ /** 16 kHz mono Float32 PCM, a file path, or a `Gio.File`. */
11
+ export type TranscribeSource = Float32Array | string | TranscribeFile;
12
+ export interface TranscribeOptions {
13
+ /** BCP 47 hint. Informational for a multilingual model, which detects the language itself. */
14
+ lang?: string;
15
+ /** Contextual biasing. Applied only where the engine supports it; `boost` is advisory. */
16
+ phrases?: readonly SpeechRecognitionPhrase[];
17
+ /** Aborts reading and decoding of a file. A decode already running in the engine cannot be interrupted. */
18
+ signal?: AbortSignal;
19
+ /** An offline model id from `RECOGNITION_MODELS`. Default: {@link DEFAULT_TRANSCRIBE_MODEL}. */
20
+ model?: string;
21
+ /** The engine for `model`. Default: sherpa-onnx on the cached files. Tests and second backends. */
22
+ engine?: (model: RecognitionModelEntry) => OfflineEngine;
23
+ }
24
+ export interface Transcription {
25
+ text: string;
26
+ /** BCP 47 primary subtag the engine detected, or `null` when it does not say. */
27
+ language: string | null;
28
+ /** Backend and model, e.g. `sherpa-onnx/parakeet-tdt-0.6b-v3-int8`. */
29
+ engine: string;
30
+ }
31
+ /**
32
+ * Recognize a finished recording. Rejects with `AbortError` on abort, `NotSupportedError` when
33
+ * there is no engine on this host, `NotFoundError` when the model is not cached
34
+ * (`await install({ langs, kind: 'offline' })` first).
35
+ */
36
+ export declare function transcribe(source: TranscribeSource, options?: TranscribeOptions): Promise<Transcription>;
@@ -0,0 +1,2 @@
1
+ declare const _default: () => Promise<void>;
2
+ export default _default;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@gjsify/speech-recognition",
3
- "version": "0.64.51",
4
- "description": "Web Speech recognition API (SpeechRecognition and its event and result classes) for GJS, running fully on the device: a streaming zipformer on sherpa-onnx, fed by @gjsify/media-capture and endpointed by @gjsify/vad. Models are fetched on first use, never bundled.",
3
+ "version": "0.64.53",
4
+ "description": "Web Speech recognition API (SpeechRecognition and its event and result classes) for GJS, running fully on the device: a streaming zipformer on sherpa-onnx, fed by @gjsify/media-capture and endpointed by @gjsify/vad, plus transcribe() for finished recordings on an offline Parakeet model. Models are fetched on first use, never bundled.",
5
5
  "type": "module",
6
6
  "module": "lib/esm/index.js",
7
7
  "types": "lib/types/index.d.ts",
@@ -45,19 +45,19 @@
45
45
  "zipformer"
46
46
  ],
47
47
  "dependencies": {
48
- "@gjsify/dom-events": "0.64.51",
49
- "@gjsify/media-capture": "0.64.51",
50
- "@gjsify/model-store": "0.64.51",
51
- "@gjsify/node-globals": "0.64.51",
52
- "@gjsify/sherpa-native": "0.64.51",
53
- "@gjsify/utils": "0.64.51",
54
- "@gjsify/vad": "0.64.51"
48
+ "@gjsify/dom-events": "0.64.53",
49
+ "@gjsify/media-capture": "0.64.53",
50
+ "@gjsify/model-store": "0.64.53",
51
+ "@gjsify/node-globals": "0.64.53",
52
+ "@gjsify/sherpa-native": "0.64.53",
53
+ "@gjsify/utils": "0.64.53",
54
+ "@gjsify/vad": "0.64.53"
55
55
  },
56
56
  "devDependencies": {
57
57
  "@girs/gjs": "5.4.0",
58
58
  "@girs/glib-2.0": "5.4.0",
59
- "@gjsify/cli": "0.64.51",
60
- "@gjsify/unit": "0.64.51",
59
+ "@gjsify/cli": "0.64.53",
60
+ "@gjsify/unit": "0.64.53",
61
61
  "@types/node": "^25.9.2",
62
62
  "typescript": "^6.0.3"
63
63
  },