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
5 changes: 5 additions & 0 deletions changes/fix-transcription-report-parity.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
### Changed — may break callers

- **`meetings transcribe` answers the same report as the other phone CLIs (beeline, b24).** The audio time is
`audio_ms`, in milliseconds (was `audio_seconds`). Each failed call has its `ref`. A call with no recording is listed
under `failed` with the reason `recording.missing`, and `without_recording` is gone.
2 changes: 1 addition & 1 deletion docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ pbx meetings transcribe [query] [options]
| `--max-meetings <n>` | at most this many calls transcribed, newest first. Default: `20`. |
| `--model <model>` | local speech model, when the profile transcribes locally. Default: `gigaam-v3`. |

**Returns:** call transcription report — transcribed, audio_seconds, failed, without_recording, remaining, stopped; every field: pbx commands info meetings transcribe
**Returns:** call transcription report — transcribed, audio_ms, failed, remaining, stopped; every field: pbx commands info meetings transcribe

**Example:** `pbx office meetings transcribe --max-meetings 20 --json`, `pbx office meetings transcribe duration_ms>=60000 --json`, `pbx office meetings transcribe id:12 --replace --json`

Expand Down
5 changes: 2 additions & 3 deletions src/commands/transcribe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,8 @@ export 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
41 changes: 22 additions & 19 deletions src/transcribe-calls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { isCliError } from "@wirecat/cli-base"
import type { QueryAst } from "@wirecat/cli-base/query"
import {
type Attachment,
formatMeetingReference,
type MeetingStore,
type MeetingTranscriptReceiptStore,
transcribeMeeting,
Expand All @@ -32,15 +33,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 attached: 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 @@ -106,21 +112,20 @@ export const transcribeCalls = async (
const calls = (await store.meetings({ accountId, query: options.query })).sort(
(a, b) => (b.startedAt ?? 0) - (a.startedAt ?? 0),
)
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,
})
const pending = []
for (const call of calls) {
const details = await store.meeting(call.id)
if (!details || (!options.replace && details.transcripts.length > 0)) continue
const recording = recordingOf(details.attachments)
if (recording) pending.push({ call, recording, speakers: speakersOf(details, ports.sides ?? null) })
else report.without_recording++
else report.failed.push(failed(call.id, "recording.missing", "the call has no recording"))
}
const shown = Math.min(pending.length, options.limit)
for (const [index, { call, recording, speakers }] of pending.entries()) {
Expand Down Expand Up @@ -150,7 +155,7 @@ export const transcribeCalls = async (
await local.dispose()
}
report.transcribed++
report.audio_seconds += Math.round((call.durationMs ?? 0) / 1000)
report.audio_ms += call.durationMs ?? 0
options.progress?.(`${index + 1}/${shown} meeting ${call.id} transcribed`)
} catch (error) {
// The run's deadline stops a read or a recognition halfway, whatever error that throws; the calls finished
Expand All @@ -162,11 +167,9 @@ 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),
message: isCliError(error) ? error.message : "the call could not be transcribed",
})
report.failed.push(
failed(call.id, String(reason), isCliError(error) ? error.message : "the call could not be transcribed"),
)
options.progress?.(`${index + 1}/${shown} meeting ${call.id} failed: ${reason}`)
}
}
Expand Down
18 changes: 14 additions & 4 deletions src/transcribe.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,18 @@ beforeEach(async () => {
expect(synced.code, synced.err).toBe(0)
})

it("transcribes the calls that have a recording, counts those without, and finds what the client said", async () => {
it("transcribes the calls that have a recording, lists those without as failed, and finds what the client said", async () => {
const done = await transcribe([], { speech: speech() })
expect(done.code, done.err).toBe(0)
expect(done.json().item).toMatchObject({ transcribed: 2, failed: [], without_recording: 3, remaining: 0 })
const item = done.json().item as { transcribed: number; audio_ms: number; failed: { ref: string; reason: string }[] }
expect(item).toMatchObject({ transcribed: 2, remaining: 0 })
expect(item.audio_ms).toBeGreaterThan(0)
expect(item.failed.map(({ reason }) => reason)).toEqual([
"recording.missing",
"recording.missing",
"recording.missing",
])
expect(item.failed.every(({ ref }) => ref.startsWith("meeting:"))).toBe(true)

const list = await runCli(["office", "meetings", "list", "--json"])
const call = (list.json().items as { id: string; title: string }[]).find(
Expand All @@ -50,7 +58,7 @@ it("transcribes the calls that have a recording, counts those without, and finds
expect(transcript.out).toContain("оплатим в пятницу")

const again = await transcribe([], { speech: speech() })
expect(again.json().item).toMatchObject({ transcribed: 0, without_recording: 3 })
expect(again.json().item).toMatchObject({ transcribed: 0, failed: [{}, {}, {}] })
})

it("lists a recording that cannot be decoded and goes on with the rest", async () => {
Expand All @@ -64,7 +72,9 @@ it("lists a recording that cannot be decoded and goes on with the rest", async (
})
const done = await transcribe([], { speech: failing })
expect(done.code, done.err).toBe(0)
expect(done.json().item).toMatchObject({ transcribed: 1, failed: [{ reason: "unexpected" }] })
const item = done.json().item as { transcribed: number; failed: { reason: string }[] }
expect(item.transcribed).toBe(1)
expect(item.failed.filter(({ reason }) => reason !== "recording.missing")).toMatchObject([{ reason: "unexpected" }])
})

it("refuses a model that is not downloaded, and says how to get it", async () => {
Expand Down
Loading