Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

feat(editor): polish auto-caption loading toasts

parse-nipa0bcd9fe9063
diff --git a/src/App.tsx b/src/App.tsx
index 6f737b9b0..78cf66c00 100644
--- a/src/App.tsx
+++ b/src/App.tsx
@@ -82,7 +82,7 @@ export default function App() {
return (
<TooltipProvider>
{content}
- <Toaster theme="dark" className="pointer-events-auto" />
+ <Toaster theme="dark" />
</TooltipProvider>
);
}
diff --git a/src/components/ui/sonner.tsx b/src/components/ui/sonner.tsx
index fe3a3906a..3076ac1fe 100644
--- a/src/components/ui/sonner.tsx
+++ b/src/components/ui/sonner.tsx
@@ -1,18 +1,22 @@
import { Toaster as Sonner } from "sonner";
+import { cn } from "@/lib/utils";
type ToasterProps = React.ComponentProps<typeof Sonner>;
-const Toaster = ({ ...props }: ToasterProps) => {
+const Toaster = ({ className, ...props }: ToasterProps) => {
return (
<Sonner
- theme="light"
- className="toaster group"
+ theme="dark"
+ className={cn(
+ "dark toaster group pointer-events-none [&_[data-sonner-toast]]:pointer-events-auto",
+ className,
+ )}
duration={3000}
toastOptions={{
classNames: {
toast:
- "group toast group-[.toaster]:bg-background group-[.toaster]:text-foreground group-[.toaster]:border-border group-[.toaster]:shadow-lg",
- description: "group-[.toast]:text-muted-foreground",
+ "group toast border border-white/10 bg-[#09090b] text-slate-200 shadow-lg backdrop-blur-xl",
+ description: "group-[.toast]:text-slate-400",
actionButton: "group-[.toast]:bg-primary group-[.toast]:text-primary-foreground",
cancelButton: "group-[.toast]:bg-muted group-[.toast]:text-muted-foreground",
},
diff --git a/src/components/video-editor/VideoEditor.tsx b/src/components/video-editor/VideoEditor.tsx
index c2d264dfa..20a801664 100644
--- a/src/components/video-editor/VideoEditor.tsx
+++ b/src/components/video-editor/VideoEditor.tsx
@@ -109,6 +109,9 @@ import {
import { UnsavedChangesDialog } from "./UnsavedChangesDialog";
import VideoPlayback, { VideoPlaybackRef } from "./VideoPlayback";
+/** Single Sonner slot for auto-caption progress so phases update in place instead of stacking. */
+const AUTO_CAPTION_PROGRESS_TOAST_ID = "auto-caption-progress";
+
function isClickInteractionType(interactionType: string | null | undefined) {
return (
interactionType === "click" ||
@@ -2030,18 +2033,18 @@ export default function VideoEditor() {
isAutoCaptioningRef.current = true;
setIsAutoCaptioning(true);
- const toastId = toast.loading(t("autoCaptions.generating"));
+ toast.loading(t("autoCaptions.generating"), { id: AUTO_CAPTION_PROGRESS_TOAST_ID });
try {
const { samples, truncated, durationSec } = await extractMono16kFromVideoUrl(videoPath);
if (!Number.isFinite(durationSec) || durationSec <= 0 || samples.length < 800) {
- toast.dismiss(toastId);
+ toast.dismiss(AUTO_CAPTION_PROGRESS_TOAST_ID);
toast.error(t("autoCaptions.noAudio"));
return;
}
const { samples: speechSamples, trimSec } = trimLeadingSilenceMono16k(samples);
if (speechSamples.length < 800) {
- toast.dismiss(toastId);
+ toast.dismiss(AUTO_CAPTION_PROGRESS_TOAST_ID);
toast.error(t("autoCaptions.noAudio"));
return;
}
@@ -2052,7 +2055,13 @@ export default function VideoEditor() {
const transcribeOptions = {
onStatus: (phase: "model" | "transcribe") => {
if (phase === "model") {
- toast.loading(t("autoCaptions.loadingModel"), { id: toastId });
+ toast.loading(t("autoCaptions.loadingModel"), {
+ id: AUTO_CAPTION_PROGRESS_TOAST_ID,
+ });
+ } else {
+ toast.loading(t("autoCaptions.transcribing"), {
+ id: AUTO_CAPTION_PROGRESS_TOAST_ID,
+ });
}
},
};
@@ -2111,7 +2120,7 @@ export default function VideoEditor() {
}
if (regions.length === 0) {
- toast.dismiss(toastId);
+ toast.dismiss(AUTO_CAPTION_PROGRESS_TOAST_ID);
toast.info(t("autoCaptions.noneHeard"));
return;
}
@@ -2120,18 +2129,18 @@ export default function VideoEditor() {
nextAnnotationIdRef.current = nextNumericId;
nextAnnotationZIndexRef.current = nextZIndex;
- toast.dismiss(toastId);
+ toast.dismiss(AUTO_CAPTION_PROGRESS_TOAST_ID);
+ const minutesTrunc = String(Math.round(MAX_CAPTION_AUDIO_SEC / 60));
if (truncated) {
- toast.info(
- t("autoCaptions.truncated", {
- minutes: String(Math.round(MAX_CAPTION_AUDIO_SEC / 60)),
- }),
- );
+ toast.success(t("autoCaptions.done", { count: String(regions.length) }), {
+ description: t("autoCaptions.truncated", { minutes: minutesTrunc }),
+ });
+ } else {
+ toast.success(t("autoCaptions.done", { count: String(regions.length) }));
}
- toast.success(t("autoCaptions.done", { count: String(regions.length) }));
} catch (e) {
console.error(e);
- toast.dismiss(toastId);
+ toast.dismiss(AUTO_CAPTION_PROGRESS_TOAST_ID);
const detail = e instanceof Error ? e.message : String(e);
toast.error(t("autoCaptions.failed"), { description: detail });
} finally {
diff --git a/src/i18n/locales/ar/editor.json b/src/i18n/locales/ar/editor.json
index 35ba08b23..de48f2614 100644
--- a/src/i18n/locales/ar/editor.json
+++ b/src/i18n/locales/ar/editor.json
@@ -53,6 +53,7 @@
"dialogCancel": "إلغاء",
"generating": "جارٍ توليد التسميات من الصوت…",
"loadingModel": "جارٍ تحميل نموذج الكلام (سيتم تنزيل ~75 ميغابايت عند الاستخدام الأول)…",
+ "transcribing": "جارٍ نسخ الكلام إلى نص…",
"busy": "توليد التسميات قيد التنفيذ بالفعل.",
"done": "تمت إضافة {{count}} تسمية.",
"noneHeard": "لم يتم الكشف عن أي كلام.",
diff --git a/src/i18n/locales/en/editor.json b/src/i18n/locales/en/editor.json
index ce62aeddc..0473efa4b 100644
--- a/src/i18n/locales/en/editor.json
+++ b/src/i18n/locales/en/editor.json
@@ -53,6 +53,7 @@
"dialogCancel": "Cancel",
"generating": "Generating captions from audio…",
"loadingModel": "Loading speech model (first use downloads ~75 MB)…",
+ "transcribing": "Transcribing speech…",
"busy": "Caption generation is already in progress.",
"done": "Added {{count}} captions.",
"noneHeard": "No speech was detected.",
diff --git a/src/i18n/locales/es/editor.json b/src/i18n/locales/es/editor.json
index c7a2c2aff..c5a75b1a1 100644
--- a/src/i18n/locales/es/editor.json
+++ b/src/i18n/locales/es/editor.json
@@ -53,6 +53,7 @@
"dialogCancel": "Cancelar",
"generating": "Generando subtítulos a partir del audio…",
"loadingModel": "Cargando el modelo de voz (el primer uso descarga ~75 MB)…",
+ "transcribing": "Transcribiendo el habla…",
"busy": "La generación de subtítulos ya está en curso.",
"done": "Se añadieron {{count}} subtítulos.",
"noneHeard": "No se detectó voz.",
diff --git a/src/i18n/locales/fr/editor.json b/src/i18n/locales/fr/editor.json
index e1acdc741..8a5506f5f 100644
--- a/src/i18n/locales/fr/editor.json
+++ b/src/i18n/locales/fr/editor.json
@@ -53,6 +53,7 @@
"dialogCancel": "Annuler",
"generating": "Génération des sous-titres à partir de l'audio…",
"loadingModel": "Chargement du modèle vocal (le premier usage télécharge ~75 MB)…",
+ "transcribing": "Transcription de la parole…",
"busy": "La génération des sous-titres est déjà en cours.",
"done": "{{count}} sous-titres ajoutés.",
"noneHeard": "Aucune parole n'a été détectée.",
diff --git a/src/i18n/locales/ja-JP/editor.json b/src/i18n/locales/ja-JP/editor.json
index fb755db6a..30c83e9cc 100644
--- a/src/i18n/locales/ja-JP/editor.json
+++ b/src/i18n/locales/ja-JP/editor.json
@@ -53,6 +53,7 @@
"dialogCancel": "キャンセル",
"generating": "音声からキャプションを生成しています…",
"loadingModel": "音声モデルを読み込んでいます(初回利用時は約 75 MB をダウンロードします)…",
+ "transcribing": "音声を文字起こししています…",
"busy": "キャプションの生成はすでに実行中です。",
"done": "{{count}} 件のキャプションを追加しました。",
"noneHeard": "音声が検出されませんでした。",
diff --git a/src/i18n/locales/ko-KR/editor.json b/src/i18n/locales/ko-KR/editor.json
index 51712b22f..e429d1b6d 100644
--- a/src/i18n/locales/ko-KR/editor.json
+++ b/src/i18n/locales/ko-KR/editor.json
@@ -53,6 +53,7 @@
"dialogCancel": "취소",
"generating": "오디오에서 자막을 생성하는 중…",
"loadingModel": "음성 모델을 불러오는 중(첫 사용 시 약 75MB 다운로드)…",
+ "transcribing": "음성을 전사하는 중…",
"busy": "자막 생성이 이미 진행 중입니다.",
"done": "자막 {{count}}개를 추가했습니다.",
"noneHeard": "음성이 감지되지 않았습니다.",
diff --git a/src/i18n/locales/tr/editor.json b/src/i18n/locales/tr/editor.json
index e85ae5ebe..475bbd3e5 100644
--- a/src/i18n/locales/tr/editor.json
+++ b/src/i18n/locales/tr/editor.json
@@ -53,6 +53,7 @@
"dialogCancel": "İptal",
"generating": "Sesten altyazılar oluşturuluyor…",
"loadingModel": "Konuşma modeli yükleniyor (ilk kullanımda ~75 MB indirilir)…",
+ "transcribing": "Konuşma yazıya dökülüyor…",
"busy": "Altyazı oluşturma zaten devam ediyor.",
"done": "{{count}} altyazı eklendi.",
"noneHeard": "Konuşma algılanmadı.",
diff --git a/src/i18n/locales/zh-CN/editor.json b/src/i18n/locales/zh-CN/editor.json
index 4f576f4c4..2b6b57425 100644
--- a/src/i18n/locales/zh-CN/editor.json
+++ b/src/i18n/locales/zh-CN/editor.json
@@ -53,6 +53,7 @@
"dialogCancel": "取消",
"generating": "正在从音频生成字幕…",
"loadingModel": "正在加载语音模型(首次使用将下载约 75 MB)…",
+ "transcribing": "正在转写语音…",
"busy": "字幕生成已在进行中。",
"done": "已添加 {{count}} 条字幕。",
"noneHeard": "未检测到语音。",
diff --git a/src/i18n/locales/zh-TW/editor.json b/src/i18n/locales/zh-TW/editor.json
index b61f408eb..dcc4dce56 100644
--- a/src/i18n/locales/zh-TW/editor.json
+++ b/src/i18n/locales/zh-TW/editor.json
@@ -53,6 +53,7 @@
"dialogCancel": "取消",
"generating": "正在從音訊產生字幕…",
"loadingModel": "正在載入語音模型(首次使用將下載約 75 MB)…",
+ "transcribing": "正在轉錄語音…",
"busy": "字幕產生已在進行中。",
"done": "已新增 {{count}} 條字幕。",
"noneHeard": "未偵測到語音。",
diff --git a/src/lib/captioning/transcribe.ts b/src/lib/captioning/transcribe.ts
index 1c649c613..83fb36510 100644
--- a/src/lib/captioning/transcribe.ts
+++ b/src/lib/captioning/transcribe.ts
@@ -18,6 +18,18 @@ function segmentOverlapsTrim(startMs: number, endMs: number, trims: TrimRegion[]
return trims.some((t) => startMs < t.endMs && endMs > t.startMs);
}
+/** Lets the browser paint toast / in-app status before Whisper blocks the main thread (WASM may not yield). */
+async function yieldForUiPaint(): Promise<void> {
+ await new Promise<void>((resolve) => setTimeout(resolve, 0));
+ await new Promise<void>((resolve) => {
+ requestAnimationFrame(() => {
+ requestAnimationFrame(() => resolve());
+ });
+ });
+ // macrotask after rAF so React/Sonner state can commit under load.
+ await new Promise<void>((resolve) => setTimeout(resolve, 0));
+}
+
/**
* ONNX Runtime's wasm bundle treats `process.versions.node` (present in Electron's
* renderer) as Node and tries `require("fs")`, which Vite does not support. Mask it
@@ -212,8 +224,13 @@ export async function transcribeMono16kToSegments(
if (options?.signal?.aborted) throw new DOMException("Aborted", "AbortError");
+ await yieldForUiPaint();
+
const trims = options?.trimRegions ?? [];
options?.onStatus?.("transcribe");
+ if (options?.signal?.aborted) throw new DOMException("Aborted", "AbortError");
+ await yieldForUiPaint();
+ if (options?.signal?.aborted) throw new DOMException("Aborted", "AbortError");
const transcribeOne = async (
ignoreTrims: boolean,