Skip to content

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

1.5 KB
Raw Blame
const { DEFAULTS, LIMITS } = require("../constants/whisperVad.json");

const DEFAULT_WHISPER_VAD_CONFIG = Object.freeze({ ...DEFAULTS });
const VAD_LIMITS = Object.freeze(LIMITS);

function clampVadField(key, value) {
  const fallback = DEFAULTS[key];
  const n = value === null || value === undefined || value === "" ? fallback : Number(value);
  if (!Number.isFinite(n)) return fallback;
  const { min, max, round } = LIMITS[key];
  const clamped = Math.min(max, Math.max(min, n));
  return round ? Math.round(clamped) : clamped;
}

function sanitizeWhisperVadConfig(input = {}) {
  const merged = { ...DEFAULTS, ...(input || {}) };
  const out = {};
  for (const key of Object.keys(DEFAULTS)) {
    out[key] = clampVadField(key, merged[key]);
  }
  return out;
}

function resolveContextSileroEnabled(settings = {}, context = "dictation") {
  // Dictation is opt-in: VAD on pause-heavy dictations can strip the speech and
  // leave Whisper decoding near-silence seeded with the dictionary prompt, which
  // replaces the transcript with dictionary words (#1454). Long-form contexts
  // (notes, meetings) keep VAD to skip extended silence.
  if (context === "dictation") return settings?.dictationSileroEnabled === true;
  if (context === "noteRecording") return settings?.noteRecordingSileroEnabled !== false;
  if (context === "meeting") return settings?.meetingSileroEnabled !== false;
  return true;
}

module.exports = {
  DEFAULT_WHISPER_VAD_CONFIG,
  VAD_LIMITS,
  clampVadField,
  sanitizeWhisperVadConfig,
  resolveContextSileroEnabled,
};