diff --git a/changes/fix-transcription-report-parity.md b/changes/fix-transcription-report-parity.md new file mode 100644 index 0000000..e51e27d --- /dev/null +++ b/changes/fix-transcription-report-parity.md @@ -0,0 +1,6 @@ +### Changed — may break callers + +- **`meetings transcribe` answers the same report as beeline.** The audio time is `audio_ms`, in milliseconds (was + `audio_seconds`). Each failed call has its `ref`. A call with no recording on the portal is listed under `failed` + with the reason `recording.missing`, and `without_recording` is gone. Before, the two CLIs answered two shapes for + the same `call_transcription_report`, and the family audit stopped beeline's pull requests. diff --git a/docs/commands.md b/docs/commands.md index be1be65..decc4e6 100644 --- a/docs/commands.md +++ b/docs/commands.md @@ -1327,7 +1327,7 @@ b24 meetings transcribe [query] [options] | `--max-meetings ` | at most this many calls transcribed, newest first. Default: `20`. | | `--model ` | local speech model. Default: `gigaam-v3`. | -**Returns:** call transcription report — transcribed, audio_seconds, failed, without_recording, remaining, stopped; every field: b24 commands info meetings transcribe +**Returns:** call transcription report — transcribed, audio_ms, failed, remaining, stopped; every field: b24 commands info meetings transcribe **Example:** `b24 work meetings transcribe --max-meetings 20 --json`, `b24 work meetings transcribe "duration_ms>=60000" --json` diff --git a/src/calls/calls.test.ts b/src/calls/calls.test.ts index 6ad4c09..ac9798e 100644 --- a/src/calls/calls.test.ts +++ b/src/calls/calls.test.ts @@ -252,18 +252,22 @@ describe("meetings transcribe", () => { await b24(["work", "meetings", "sync", "--json"], { portal }) const ran = await transcribe(portal) expect(ran.code, ran.err).toBe(0) - expect(JSON.parse(ran.out).item).toMatchObject({ transcribed: 1, failed: [], without_recording: 0 }) + expect(JSON.parse(ran.out).item).toMatchObject({ transcribed: 1, failed: [] }) expect(statistic(portal).at(-1)?.body).toEqual({ FILTER: { CALL_ID: "externalCall.1" } }) const transcript = await b24(["work", "meetings", "transcript", "1", "--json"], { portal }) expect(transcript.out).toContain("Добрый день, это Ольга") expect(readdirSync(process.env.B24_STATE_DIR as string)).not.toContain("recordings") }) - it("counts a call with no recording on the portal and goes on", async () => { + it("lists a call with no recording on the portal as failed, named by its ref, and goes on", async () => { const portal = portalWith([row(1)]) await b24(["work", "meetings", "sync", "--json"], { portal }) const ran = await transcribe(portal) - expect(JSON.parse(ran.out).item).toMatchObject({ transcribed: 0, without_recording: 1 }) + expect(JSON.parse(ran.out).item).toMatchObject({ + transcribed: 0, + audio_ms: 0, + failed: [{ meeting: 1, ref: expect.stringMatching(/^meeting:/), reason: "recording.missing" }], + }) }) it("keeps the recording with download_recordings, and reads the kept file the next time", async () => { diff --git a/src/calls/transcribe.ts b/src/calls/transcribe.ts index 9634dd0..260b4ad 100644 --- a/src/calls/transcribe.ts +++ b/src/calls/transcribe.ts @@ -3,6 +3,7 @@ import { readFile } from "node:fs/promises" import { isCliError } from "@wirecat/cli-base" import type { QueryAst } from "@wirecat/cli-base/query" import { + formatMeetingReference, type MeetingRecognitionSegment, type MeetingStore, type MeetingTranscriptionSource, @@ -35,15 +36,20 @@ export interface TranscribeOptions { export interface TranscribeReport { transcribed: number - audio_seconds: number - failed: { meeting: number; reason: string; message: string }[] - /** Calls the query names that have no recording on the portal: nothing to transcribe. */ - without_recording: number + audio_ms: number + failed: FailedCall[] remaining: number /** True when the run stopped on its signal before reaching --max-meetings. */ stopped: boolean } +export interface FailedCall { + meeting: number + ref: string + reason: string + message: string +} + export interface TranscribePorts { store: MeetingStore & MeetingTranscriptReceiptStore accountId: number @@ -129,23 +135,18 @@ export const transcribeCalls = async ( (a, b) => (b.startedAt ?? 0) - (a.startedAt ?? 0), ) const pending = [] - const report: TranscribeReport = { - transcribed: 0, - audio_seconds: 0, - failed: [], - without_recording: 0, - remaining: 0, - stopped: false, - } + const report: TranscribeReport = { transcribed: 0, audio_ms: 0, failed: [], remaining: 0, stopped: false } + const failed = (meeting: number, reason: string, message: string): FailedCall => ({ + meeting, + ref: formatMeetingReference({ type: "meeting", accountId, meetingId: meeting }), + reason, + message, + }) for (const call of calls) { const details = await store.meeting(call.id) if (!details || !(options.replace || details.transcripts.length === 0)) continue if ((call.durationMs ?? 0) > LONGEST_CALL_MS) - report.failed.push({ - meeting: call.id, - reason: "recording.too-long", - message: "the call is longer than 60 minutes", - }) + report.failed.push(failed(call.id, "recording.too-long", "the call is longer than 60 minutes")) else pending.push(call) } for (const [index, call] of pending.entries()) { @@ -158,8 +159,8 @@ export const transcribeCalls = async ( try { const found = await recordingOf(ports, call.externalId) if (!found) { - report.without_recording++ - options.progress?.(`${step} has no recording`) + report.failed.push(failed(call.id, "recording.missing", "the call has no recording on the portal")) + options.progress?.(`${step} failed: recording.missing`) continue } const channels = await ports.decode(found.bytes) @@ -171,7 +172,7 @@ export const transcribeCalls = async ( await keepAttachment(store, call.id, attachmentOf(path, found.bytes.byteLength, found.record), now) } report.transcribed++ - report.audio_seconds += Math.round(durationMsOf(channels) / 1000) + report.audio_ms += durationMsOf(channels) options.progress?.(`${step} transcribed`) } catch (error) { // The run's deadline stops a download or a recognition halfway, whatever error that throws; the calls finished @@ -183,12 +184,14 @@ export const transcribeCalls = async ( } if (isCliError(error) && error.code === "cancelled") throw error const reason = isCliError(error) ? (error.details.reason ?? error.code) : "unexpected" - report.failed.push({ - meeting: call.id, - reason: String(reason), - // Only b24's and cli-core's own errors are worded for the answer; any other may carry a path or a link. - message: isCliError(error) ? error.message : "the call could not be transcribed", - }) + report.failed.push( + failed( + call.id, + String(reason), + // Only b24's and cli-core's own errors are worded for the answer; any other may carry a path or a link. + isCliError(error) ? error.message : "the call could not be transcribed", + ), + ) options.progress?.(`${step} failed: ${reason}`) } } diff --git a/src/commands/transcribe.ts b/src/commands/transcribe.ts index 59e95d4..ae79742 100644 --- a/src/commands/transcribe.ts +++ b/src/commands/transcribe.ts @@ -60,9 +60,8 @@ const callQuery = (text: string) => { const REPORT = v.strictObject({ transcribed: v.number(), - audio_seconds: v.number(), - failed: v.array(v.strictObject({ meeting: v.number(), reason: v.string(), message: v.string() })), - without_recording: v.number(), + audio_ms: v.number(), + failed: v.array(v.strictObject({ meeting: v.number(), ref: v.string(), reason: v.string(), message: v.string() })), remaining: v.number(), stopped: v.boolean(), })