@monoclaw/machine 1.0.12 → 1.0.13
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/cli.js +50 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -2402,7 +2402,55 @@ function encodeWavPcm16(samples, sampleRate) {
|
|
|
2402
2402
|
}
|
|
2403
2403
|
|
|
2404
2404
|
// ../../packages/voice-engine/src/stt.ts
|
|
2405
|
+
var STT_PIECE_SECONDS = 120;
|
|
2406
|
+
var CUT_SEARCH_SECONDS = 8;
|
|
2407
|
+
var CUT_WINDOW_SECONDS = 0.1;
|
|
2408
|
+
function cutPoints(samples, sampleRate, pieceSeconds = STT_PIECE_SECONDS) {
|
|
2409
|
+
const piece = Math.floor(pieceSeconds * sampleRate);
|
|
2410
|
+
const search = Math.floor(Math.min(CUT_SEARCH_SECONDS, pieceSeconds / 4) * sampleRate);
|
|
2411
|
+
const win = Math.max(1, Math.floor(CUT_WINDOW_SECONDS * sampleRate));
|
|
2412
|
+
const cuts = [];
|
|
2413
|
+
let start = 0;
|
|
2414
|
+
while (samples.length - start > piece) {
|
|
2415
|
+
const limit = start + piece;
|
|
2416
|
+
let best = limit;
|
|
2417
|
+
let bestEnergy = Infinity;
|
|
2418
|
+
for (let at = limit - search; at + win <= limit; at += win) {
|
|
2419
|
+
let e = 0;
|
|
2420
|
+
for (let i = at; i < at + win; i++) e += samples[i] * samples[i];
|
|
2421
|
+
if (e < bestEnergy) {
|
|
2422
|
+
bestEnergy = e;
|
|
2423
|
+
best = at + Math.floor(win / 2);
|
|
2424
|
+
}
|
|
2425
|
+
}
|
|
2426
|
+
cuts.push(best);
|
|
2427
|
+
start = best;
|
|
2428
|
+
}
|
|
2429
|
+
return cuts;
|
|
2430
|
+
}
|
|
2405
2431
|
async function transcribe(mgr, modelId, samples, sampleRate, withTimestamps) {
|
|
2432
|
+
const cuts = cutPoints(samples, sampleRate);
|
|
2433
|
+
if (!cuts.length) return transcribeOne(mgr, modelId, samples, sampleRate, withTimestamps);
|
|
2434
|
+
const bounds = [0, ...cuts, samples.length];
|
|
2435
|
+
const texts = [];
|
|
2436
|
+
const words = [];
|
|
2437
|
+
let language = null;
|
|
2438
|
+
for (let i = 0; i < bounds.length - 1; i++) {
|
|
2439
|
+
const from = bounds[i];
|
|
2440
|
+
const part = await transcribeOne(mgr, modelId, samples.subarray(from, bounds[i + 1]), sampleRate, withTimestamps);
|
|
2441
|
+
if (part.text) texts.push(part.text);
|
|
2442
|
+
language ??= part.language;
|
|
2443
|
+
const offset = from / sampleRate;
|
|
2444
|
+
for (const w of part.words ?? []) words.push({ word: w.word, start: round(w.start + offset), end: round(w.end + offset) });
|
|
2445
|
+
}
|
|
2446
|
+
const out = { text: texts.join(" ").replace(/\s+/g, " ").trim(), durationSeconds: samples.length / sampleRate, language };
|
|
2447
|
+
if (withTimestamps) {
|
|
2448
|
+
out.words = words;
|
|
2449
|
+
out.segments = segmentsFromWords(words);
|
|
2450
|
+
}
|
|
2451
|
+
return out;
|
|
2452
|
+
}
|
|
2453
|
+
async function transcribeOne(mgr, modelId, samples, sampleRate, withTimestamps) {
|
|
2406
2454
|
const rec = mgr.recognizer(modelId);
|
|
2407
2455
|
if (!rec) throw new Error(`model ${modelId} is not loaded`);
|
|
2408
2456
|
const stream = rec.createStream();
|
|
@@ -2882,7 +2930,7 @@ var Engine = class {
|
|
|
2882
2930
|
rate = parsed.sampleRate;
|
|
2883
2931
|
} else throw new EngineError("bad_audio", "audio or samples required");
|
|
2884
2932
|
if (rate !== 16e3) samples = resampleLinear(samples, rate, 16e3);
|
|
2885
|
-
if (samples.length / 16e3 >
|
|
2933
|
+
if (samples.length / 16e3 > 1800) throw new EngineError("too_long", "audio longer than 30 minutes");
|
|
2886
2934
|
try {
|
|
2887
2935
|
const out = await this.queue.run(() => transcribe(this.manager, model, samples, 16e3, req.timestamps ?? false), req.queueTimeoutMs ?? 12e4, req.caller);
|
|
2888
2936
|
return { ...out, model, latencyMs: Date.now() - t0 };
|
|
@@ -4322,7 +4370,7 @@ function guessMime(name) {
|
|
|
4322
4370
|
}
|
|
4323
4371
|
|
|
4324
4372
|
// src/version.ts
|
|
4325
|
-
var APP_VERSION = true ? "1.0.
|
|
4373
|
+
var APP_VERSION = true ? "1.0.13" : fromPackage();
|
|
4326
4374
|
|
|
4327
4375
|
// src/diag.ts
|
|
4328
4376
|
var MAX_HELD = 200;
|
package/npm-shrinkwrap.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@monoclaw/machine",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"lockfileVersion": 3,
|
|
5
5
|
"requires": true,
|
|
6
6
|
"packages": {
|
|
7
7
|
"": {
|
|
8
8
|
"name": "@monoclaw/machine",
|
|
9
|
-
"version": "1.0.
|
|
9
|
+
"version": "1.0.13",
|
|
10
10
|
"license": "UNLICENSED",
|
|
11
11
|
"dependencies": {
|
|
12
12
|
"@anthropic-ai/claude-agent-sdk": "0.3.302",
|
package/package.json
CHANGED