Skip to content

Voice-to-text dictation app with local (Nvidia Parakeet/Whisper) and cloud models (BYOK). Privacy-first and available cross-platform.

1.4 KB
Raw Blame
import { DICTIONARY_ECHO_CODE } from "../utils/dictionaryEchoFilter.js";
import { IPC_ERROR_FIELDS } from "./ipcErrorFields.js";

// How a transcription failure ends, for batch recordings and re-uploaded
// streaming ones alike. Silence is not reported. A transcript discarded as an
// echo of the dictionary prompt, or audio Cloud found no speech in, reads as
// silence, but its recording is kept for a manual retry like any real
// failure's, or the utterance vanishes (#1547).
export const transcriptionFailureOutcome = (error) => {
  if (error.code === DICTIONARY_ECHO_CODE || error.code === "NO_SPEECH_DETECTED") {
    return { noAudio: true, keepAudio: true, report: null };
  }
  if (error.message === "No audio detected") {
    return { noAudio: true, keepAudio: false, report: null };
  }
  const report = {
    title: error.selectionEditFatal ? "Selection Edit Failed" : "Transcription Error",
    ...(error.selectionEditFatal ? { selectionEditFatal: true } : {}),
    description: error.selectionEditFatal
      ? error.message
      : `Transcription failed: ${error.message}`,
  };
  for (const key of IPC_ERROR_FIELDS) {
    if (error[key] !== undefined) report[key] = error[key];
  }
  // A transcript that outlived a later failure gets the pill's View Transcript.
  if (error.transcript) report.transcript = error.transcript;
  return { noAudio: false, keepAudio: true, report };
};