Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions changes/fix-transcription-report-parity.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -1327,7 +1327,7 @@ b24 meetings transcribe [query] [options]
| `--max-meetings <n>` | at most this many calls transcribed, newest first. Default: `20`. |
| `--model <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`

Expand Down
10 changes: 7 additions & 3 deletions src/calls/calls.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand Down
55 changes: 29 additions & 26 deletions src/calls/transcribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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()) {
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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}`)
}
}
Expand Down
5 changes: 2 additions & 3 deletions src/commands/transcribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
})
Expand Down
Loading