feat: add transcription diagnostics for empty result bug
This commit is contained in:
1 parent
b111ae0a76
commit
b2554006a4
7 files changed
+303
-11
No files matched your search
+53
-4
@@ -41,9 +41,22 @@ export interface ModelWithStatus {
|
||||
localPath?: string | null;
|
||||
}
|
||||
|
||||
export interface TranscriptionAttempt {
|
||||
stage: string;
|
||||
audioPath: string;
|
||||
audioSizeBytes: number;
|
||||
sidecar: string;
|
||||
model: string;
|
||||
exitCode: number | null;
|
||||
stdoutTail: string;
|
||||
stderrTail: string;
|
||||
error: string | null;
|
||||
}
|
||||
|
||||
export interface TranscriptDraft {
|
||||
text: string;
|
||||
lastMessage: string | null;
|
||||
lastAttempt?: TranscriptionAttempt;
|
||||
}
|
||||
|
||||
export interface AppSnapshot {
|
||||
@@ -121,8 +134,25 @@ function element<K extends keyof HTMLElementTagNameMap>(
|
||||
}
|
||||
|
||||
function formatBytes(bytes: number): string {
|
||||
const mib = bytes / 1024 / 1024;
|
||||
return `${mib.toFixed(0)} MiB`;
|
||||
if (bytes < 1024) return `${bytes} B`;
|
||||
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
||||
return `${(bytes / 1024 / 1024).toFixed(2)} MB`;
|
||||
}
|
||||
|
||||
function formatAttempt(attempt: TranscriptionAttempt): string {
|
||||
const lines = [
|
||||
`stage: ${attempt.stage}`,
|
||||
`audio: ${attempt.audioPath} (${formatBytes(attempt.audioSizeBytes)})`,
|
||||
`sidecar: ${attempt.sidecar}`,
|
||||
`model: ${attempt.model}`,
|
||||
`exitCode: ${attempt.exitCode ?? "n/a"}`,
|
||||
`error: ${attempt.error ?? "—"}`,
|
||||
`stdout:`,
|
||||
attempt.stdoutTail || "(vazio)",
|
||||
`stderr:`,
|
||||
attempt.stderrTail || "(vazio)",
|
||||
];
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
function modelStatusLabel(status: ModelWithStatus["status"]): string {
|
||||
@@ -221,7 +251,17 @@ export function createTranscriptionApp(
|
||||
) as HTMLButtonElement;
|
||||
modelPanel.append(modelTitle, modelDetails, modelStatus, downloadModelButton);
|
||||
|
||||
shell.append(topbar, editorLabel, editor, message, actions, modelPanel);
|
||||
const diagnostics = element("details", "diagnostics");
|
||||
const diagnosticsSummary = element(
|
||||
"summary",
|
||||
"diagnostics-summary",
|
||||
"Detalhes técnicos",
|
||||
);
|
||||
const diagnosticsBody = element("pre", "diagnostics-body");
|
||||
diagnostics.append(diagnosticsSummary, diagnosticsBody);
|
||||
diagnostics.open = false;
|
||||
|
||||
shell.append(topbar, editorLabel, editor, message, actions, modelPanel, diagnostics);
|
||||
mount.append(shell);
|
||||
|
||||
const render = (next: AppSnapshot): void => {
|
||||
@@ -248,6 +288,14 @@ export function createTranscriptionApp(
|
||||
downloadModelButton.disabled = firstModelStatus?.status === "ready";
|
||||
downloadModelButton.textContent =
|
||||
firstModelStatus?.status === "ready" ? "Modelo pronto" : "Baixar modelo";
|
||||
|
||||
const attempt = snapshot.transcript.lastAttempt;
|
||||
if (attempt) {
|
||||
diagnostics.open = true;
|
||||
diagnosticsBody.textContent = formatAttempt(attempt);
|
||||
} else {
|
||||
diagnosticsBody.textContent = "Nenhuma tentativa registrada ainda.";
|
||||
}
|
||||
};
|
||||
|
||||
const refresh = async (): Promise<void> => {
|
||||
@@ -255,7 +303,8 @@ export function createTranscriptionApp(
|
||||
};
|
||||
|
||||
const showError = (error: unknown): void => {
|
||||
message.textContent = error instanceof Error ? error.message : String(error);
|
||||
message.textContent =
|
||||
error instanceof Error ? error.message : String(error);
|
||||
};
|
||||
|
||||
const toggleRecording = async (): Promise<void> => {
|
||||
|
||||
Reference in new issue
Block a user