@auxiora/stt 1.10.0 → 1.10.5

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/dist/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export type { AudioFormat, STTOptions, Transcription, STTProvider } from './types.js';
2
2
  export { pcmToWav } from './pcm-to-wav.js';
3
3
  export { WhisperSTT, type WhisperSTTConfig } from './whisper.js';
4
+ export { WhisperLocalSTT, type WhisperLocalConfig } from './whisper-local.js';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACtF,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACtF,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,KAAK,gBAAgB,EAAE,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,eAAe,EAAE,KAAK,kBAAkB,EAAE,MAAM,oBAAoB,CAAC"}
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { pcmToWav } from './pcm-to-wav.js';
2
2
  export { WhisperSTT } from './whisper.js';
3
+ export { WhisperLocalSTT } from './whisper-local.js';
3
4
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAyB,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAyB,MAAM,cAAc,CAAC;AACjE,OAAO,EAAE,eAAe,EAA2B,MAAM,oBAAoB,CAAC"}
@@ -0,0 +1,15 @@
1
+ import type { STTProvider, STTOptions, Transcription } from './types.js';
2
+ export interface WhisperLocalConfig {
3
+ binaryPath: string;
4
+ modelPath: string;
5
+ timeoutMs?: number;
6
+ }
7
+ export declare class WhisperLocalSTT implements STTProvider {
8
+ readonly name = "whisper-local";
9
+ private binaryPath;
10
+ private modelPath;
11
+ private timeoutMs;
12
+ constructor(config: WhisperLocalConfig);
13
+ transcribe(audio: Buffer, options?: STTOptions): Promise<Transcription>;
14
+ }
15
+ //# sourceMappingURL=whisper-local.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"whisper-local.d.ts","sourceRoot":"","sources":["../src/whisper-local.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAQzE,MAAM,WAAW,kBAAkB;IACjC,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,eAAgB,YAAW,WAAW;IACjD,QAAQ,CAAC,IAAI,mBAAmB;IAChC,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,SAAS,CAAS;IAC1B,OAAO,CAAC,SAAS,CAAS;gBAEd,MAAM,EAAE,kBAAkB;IAMhC,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,UAAU,GAAG,OAAO,CAAC,aAAa,CAAC;CA+C9E"}
@@ -0,0 +1,60 @@
1
+ import { execFile } from 'node:child_process';
2
+ import { mkdtemp, writeFile, unlink } from 'node:fs/promises';
3
+ import { tmpdir } from 'node:os';
4
+ import { join } from 'node:path';
5
+ import { promisify } from 'node:util';
6
+ import { getLogger } from '@auxiora/logger';
7
+ import { pcmToWav } from './pcm-to-wav.js';
8
+ const logger = getLogger('stt:whisper-local');
9
+ const execFileAsync = promisify(execFile);
10
+ const MIN_AUDIO_BYTES = 16000; // 0.5s at 16kHz 16-bit mono
11
+ export class WhisperLocalSTT {
12
+ name = 'whisper-local';
13
+ binaryPath;
14
+ modelPath;
15
+ timeoutMs;
16
+ constructor(config) {
17
+ this.binaryPath = config.binaryPath;
18
+ this.modelPath = config.modelPath;
19
+ this.timeoutMs = config.timeoutMs ?? 30_000;
20
+ }
21
+ async transcribe(audio, options) {
22
+ if (audio.length < MIN_AUDIO_BYTES) {
23
+ throw new Error('Audio too short');
24
+ }
25
+ const sampleRate = options?.sampleRate ?? 16000;
26
+ const wav = pcmToWav(audio, sampleRate);
27
+ const tmpDir = await mkdtemp(join(tmpdir(), 'whisper-'));
28
+ const tmpFile = join(tmpDir, 'audio.wav');
29
+ try {
30
+ await writeFile(tmpFile, wav);
31
+ const args = [
32
+ '--model', this.modelPath,
33
+ '--output-format', 'json',
34
+ '--file', tmpFile,
35
+ ];
36
+ if (options?.language) {
37
+ args.push('--language', options.language);
38
+ }
39
+ logger.info('Running whisper.cpp', { binaryPath: this.binaryPath, audioBytes: audio.length, sampleRate });
40
+ const { stdout } = await execFileAsync(this.binaryPath, args, {
41
+ timeout: this.timeoutMs,
42
+ });
43
+ const parsed = JSON.parse(stdout);
44
+ logger.info('Transcription complete', {
45
+ textLength: parsed.text.length,
46
+ language: parsed.language,
47
+ duration: parsed.duration,
48
+ });
49
+ return {
50
+ text: parsed.text.trim(),
51
+ language: parsed.language ?? options?.language ?? 'en',
52
+ duration: parsed.duration ?? 0,
53
+ };
54
+ }
55
+ finally {
56
+ await unlink(tmpFile).catch(() => { });
57
+ }
58
+ }
59
+ }
60
+ //# sourceMappingURL=whisper-local.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"whisper-local.js","sourceRoot":"","sources":["../src/whisper-local.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAC9C,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAC9D,OAAO,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAEtC,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAC;AAG3C,MAAM,MAAM,GAAG,SAAS,CAAC,mBAAmB,CAAC,CAAC;AAE9C,MAAM,aAAa,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;AAE1C,MAAM,eAAe,GAAG,KAAK,CAAC,CAAC,4BAA4B;AAQ3D,MAAM,OAAO,eAAe;IACjB,IAAI,GAAG,eAAe,CAAC;IACxB,UAAU,CAAS;IACnB,SAAS,CAAS;IAClB,SAAS,CAAS;IAE1B,YAAY,MAA0B;QACpC,IAAI,CAAC,UAAU,GAAG,MAAM,CAAC,UAAU,CAAC;QACpC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,MAAM,CAAC,SAAS,IAAI,MAAM,CAAC;IAC9C,CAAC;IAED,KAAK,CAAC,UAAU,CAAC,KAAa,EAAE,OAAoB;QAClD,IAAI,KAAK,CAAC,MAAM,GAAG,eAAe,EAAE,CAAC;YACnC,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;QACrC,CAAC;QAED,MAAM,UAAU,GAAG,OA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AAE,MAAM,CAAC,QAAQ,IAAI,OAAO,EAAE,QAAQ,IAAI,IAAI;gBACtD,QAAQ,EAAE,MAAM,CAAC,QAAQ,IAAI,CAAC;aAC/B,CAAC;QACJ,CAAC;gBAAS,CAAC;YACT,MAAM,MAAM,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,GAAG,EAAE,GAAE,CAAC,CAAC,CAAC;QACxC,CAAC;IACH,CAAC;CACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@auxiora/stt",
3
- "version": "1.10.0",
3
+ "version": "1.10.5",
4
4
  "type": "module",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
@@ -14,7 +14,7 @@
14
14
  "node": ">=22.0.0"
15
15
  },
16
16
  "dependencies": {
17
- "@auxiora/logger": "1.10.0"
17
+ "@auxiora/logger": "1.10.5"
18
18
  },
19
19
  "publishConfig": {
20
20
  "access": "public"