@agentproto/corpus-cli 0.9.4 → 0.10.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/dist/cli.mjs +72 -8
- package/dist/cli.mjs.map +1 -1
- package/dist/ports/index.d.ts +25 -0
- package/dist/ports/index.mjs +72 -8
- package/dist/ports/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/cli.mjs
CHANGED
|
@@ -1100,12 +1100,26 @@ var YtDlpWhisperFetcher = class {
|
|
|
1100
1100
|
try {
|
|
1101
1101
|
const t = await this.stt.transcribe(dl.audioPath);
|
|
1102
1102
|
if (!t.text.trim()) return null;
|
|
1103
|
+
const utterances = t.utterances ?? [];
|
|
1104
|
+
const diarized = utterances.length > 0;
|
|
1105
|
+
const speakers = diarized ? new Set(utterances.map((u) => u.speaker)).size : 0;
|
|
1103
1106
|
return {
|
|
1104
1107
|
title: dl.title || url,
|
|
1105
1108
|
text: t.text,
|
|
1106
1109
|
kind: "video",
|
|
1107
1110
|
...t.language ?? dl.language ? { language: t.language ?? dl.language } : {},
|
|
1108
|
-
via: "transcription"
|
|
1111
|
+
via: diarized ? "diarized-transcription" : "transcription",
|
|
1112
|
+
...diarized ? {
|
|
1113
|
+
metadata: {
|
|
1114
|
+
speech: {
|
|
1115
|
+
regime: "spoken",
|
|
1116
|
+
diarized: true,
|
|
1117
|
+
engine: t.engine ?? "unknown",
|
|
1118
|
+
speakers,
|
|
1119
|
+
...t.speakerLabelsLocalToSegment ? { segmented: true } : {}
|
|
1120
|
+
}
|
|
1121
|
+
}
|
|
1122
|
+
} : {}
|
|
1109
1123
|
};
|
|
1110
1124
|
} catch (e) {
|
|
1111
1125
|
if (isAuthError(e)) throw e;
|
|
@@ -1405,10 +1419,24 @@ var UPLOAD_RESPONSE = z.object({ upload_url: z.string() });
|
|
|
1405
1419
|
var AAI_TRANSCRIPT = z.object({
|
|
1406
1420
|
id: z.string(),
|
|
1407
1421
|
status: z.enum(["queued", "processing", "completed", "error"]),
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1422
|
+
// Nullish, not optional: while a job is `queued`/`processing`
|
|
1423
|
+
// AssemblyAI sends an explicit `null` for these, and the poll loop
|
|
1424
|
+
// parses every intermediate response — an `.optional()` here rejected
|
|
1425
|
+
// the very first poll of every transcript (0/64 on the Werber corpus).
|
|
1426
|
+
text: z.string().nullish(),
|
|
1427
|
+
language_code: z.string().nullish(),
|
|
1428
|
+
error: z.string().nullish(),
|
|
1429
|
+
utterances: z.array(
|
|
1430
|
+
z.object({
|
|
1431
|
+
speaker: z.string(),
|
|
1432
|
+
text: z.string(),
|
|
1433
|
+
// AssemblyAI reports these in milliseconds. Nullish, not just
|
|
1434
|
+
// optional: an explicit `null` from the API must parse cleanly
|
|
1435
|
+
// rather than failing the whole video's transcript.
|
|
1436
|
+
start: z.number().nullish(),
|
|
1437
|
+
end: z.number().nullish()
|
|
1438
|
+
})
|
|
1439
|
+
).nullish()
|
|
1412
1440
|
}).loose();
|
|
1413
1441
|
var AssemblyAiStt = class {
|
|
1414
1442
|
apiKey;
|
|
@@ -1448,9 +1476,12 @@ var AssemblyAiStt = class {
|
|
|
1448
1476
|
job = await this.get(`/transcript/${id}`);
|
|
1449
1477
|
}
|
|
1450
1478
|
if (job.status === "error") throw new Error(`AssemblyAI transcript failed: ${job.error ?? "unknown"}`);
|
|
1479
|
+
const utterances = toUtterances(job);
|
|
1451
1480
|
return {
|
|
1452
1481
|
text: formatDiarized(job),
|
|
1453
|
-
|
|
1482
|
+
engine: "assemblyai",
|
|
1483
|
+
...job.language_code ? { language: job.language_code } : {},
|
|
1484
|
+
...utterances ? { utterances } : {}
|
|
1454
1485
|
};
|
|
1455
1486
|
}
|
|
1456
1487
|
async post(path6, body) {
|
|
@@ -1468,6 +1499,15 @@ var AssemblyAiStt = class {
|
|
|
1468
1499
|
return AAI_TRANSCRIPT.parse(await r.json());
|
|
1469
1500
|
}
|
|
1470
1501
|
};
|
|
1502
|
+
function toUtterances(job) {
|
|
1503
|
+
if (!job.utterances || job.utterances.length === 0) return void 0;
|
|
1504
|
+
return job.utterances.map((u) => ({
|
|
1505
|
+
speaker: u.speaker,
|
|
1506
|
+
text: u.text.trim(),
|
|
1507
|
+
...u.start != null ? { start: u.start / 1e3 } : {},
|
|
1508
|
+
...u.end != null ? { end: u.end / 1e3 } : {}
|
|
1509
|
+
}));
|
|
1510
|
+
}
|
|
1471
1511
|
function formatDiarized(job) {
|
|
1472
1512
|
if (job.utterances && job.utterances.length > 0) {
|
|
1473
1513
|
return job.utterances.map((u) => `Speaker ${u.speaker}: ${u.text.trim()}`).join("\n\n").trim();
|
|
@@ -1498,17 +1538,39 @@ var ChunkedStt = class {
|
|
|
1498
1538
|
return this.base.transcribe(audioPath);
|
|
1499
1539
|
}
|
|
1500
1540
|
const texts = [];
|
|
1541
|
+
const utterances = [];
|
|
1542
|
+
let hasUtterances = false;
|
|
1501
1543
|
let language;
|
|
1544
|
+
let engine;
|
|
1545
|
+
let offset = 0;
|
|
1502
1546
|
let failed = 0;
|
|
1503
1547
|
let firstErr;
|
|
1504
|
-
for (const part of parts) {
|
|
1548
|
+
for (const [i, part] of parts.entries()) {
|
|
1505
1549
|
try {
|
|
1506
1550
|
const t = await this.base.transcribe(part);
|
|
1507
1551
|
if (t.text.trim()) texts.push(t.text.trim());
|
|
1508
1552
|
language ??= t.language;
|
|
1553
|
+
engine ??= t.engine;
|
|
1554
|
+
let span;
|
|
1555
|
+
if (t.utterances && t.utterances.length > 0) {
|
|
1556
|
+
hasUtterances = true;
|
|
1557
|
+
const partOffset = offset;
|
|
1558
|
+
for (const u of t.utterances) {
|
|
1559
|
+
utterances.push({
|
|
1560
|
+
speaker: `${u.speaker}#${i}`,
|
|
1561
|
+
text: u.text,
|
|
1562
|
+
...u.start !== void 0 ? { start: u.start + partOffset } : {},
|
|
1563
|
+
...u.end !== void 0 ? { end: u.end + partOffset } : {}
|
|
1564
|
+
});
|
|
1565
|
+
}
|
|
1566
|
+
const ends = t.utterances.map((u) => u.end).filter((e) => e !== void 0);
|
|
1567
|
+
if (ends.length > 0) span = Math.max(...ends);
|
|
1568
|
+
}
|
|
1569
|
+
offset += span ?? this.segmentSeconds;
|
|
1509
1570
|
} catch (e) {
|
|
1510
1571
|
failed++;
|
|
1511
1572
|
firstErr ??= e;
|
|
1573
|
+
offset += this.segmentSeconds;
|
|
1512
1574
|
}
|
|
1513
1575
|
}
|
|
1514
1576
|
if (texts.length === 0) {
|
|
@@ -1522,7 +1584,9 @@ var ChunkedStt = class {
|
|
|
1522
1584
|
}
|
|
1523
1585
|
return {
|
|
1524
1586
|
text: texts.join("\n\n"),
|
|
1525
|
-
...language ? { language } : {}
|
|
1587
|
+
...language ? { language } : {},
|
|
1588
|
+
...engine ? { engine } : {},
|
|
1589
|
+
...hasUtterances ? { utterances, speakerLabelsLocalToSegment: true } : {}
|
|
1526
1590
|
};
|
|
1527
1591
|
} finally {
|
|
1528
1592
|
await rm(dir, { recursive: true, force: true }).catch(() => {
|