Skip to content

armgit / Handy

Public Imported from GitHub
0

A free, open source, and extensible speech-to-text application that works completely offline.

state update for decoding a file

CJ Pais815e73f6cdcd
diff --git a/src/components/FileDropOverlay.tsx b/src/components/FileDropOverlay.tsx
index 72d09382..376f140c 100644
--- a/src/components/FileDropOverlay.tsx
+++ b/src/components/FileDropOverlay.tsx
@@ -5,7 +5,7 @@ import HandyHand from "./icons/HandyHand";
import { transcribeFiles } from "./settings/history/transcribeFiles";
interface FileDropOverlayProps {
- // Called once the dropped files are added, to show them in History.
+ // Called as files are dropped, to show them in History.
onDropped: () => void;
}
@@ -26,7 +26,9 @@ export const FileDropOverlay: React.FC<FileDropOverlayProps> = ({
} else if (payload.type === "drop") {
setDragging(false);
if (payload.paths.length === 0) return;
- if ((await transcribeFiles(payload.paths)) > 0) onDropped();
+ // History shows each file while it's read.
+ onDropped();
+ await transcribeFiles(payload.paths);
}
});
return () => {
diff --git a/src/components/settings/history/HistorySettings.tsx b/src/components/settings/history/HistorySettings.tsx
index 46c8eefa..f035e75d 100644
--- a/src/components/settings/history/HistorySettings.tsx
+++ b/src/components/settings/history/HistorySettings.tsx
@@ -35,7 +35,11 @@ import { formatDateTime } from "@/utils/dateFormat";
import { AudioPlayer, AudioPlayerGroup } from "../../ui/AudioPlayer";
import { Button } from "../../ui/Button";
import { copyToClipboard } from "./clipboard";
-import { pickAndTranscribeFiles } from "./transcribeFiles";
+import {
+ pickAndTranscribeFiles,
+ useFileReadsStore,
+ type FileRead,
+} from "./transcribeFiles";
const IconButton: React.FC<{
onClick: () => void;
@@ -63,6 +67,40 @@ const PAGE_SIZE = 30;
// Long text folds to this many lines until "Show more".
const FOLDED_LINES = 4;
+// The pulse of an entry's text while it's being transcribed.
+const TRANSCRIBE_PULSE = {
+ animation: "transcribe-pulse 3s ease-in-out infinite",
+};
+
+const TranscribePulseKeyframes: React.FC = () => (
+ <style>{`
+ @keyframes transcribe-pulse {
+ 0%, 100% { color: var(--color-ink-3); }
+ 50% { color: var(--color-text); }
+ }
+ `}</style>
+);
+
+// A dropped or picked file while its audio is read, before it's an entry.
+const FileReadRow: React.FC<{ read: FileRead }> = ({ read }) => {
+ const { t } = useTranslation();
+ return (
+ <div className="px-4 py-2 pb-5 flex flex-col gap-3">
+ <span
+ className="flex items-center gap-1 min-w-0 h-7 text-sm text-ink-3"
+ title={read.name}
+ >
+ <FileAudio width={14} height={14} className="shrink-0" />
+ <span className="truncate">{read.name}</span>
+ </span>
+ <p className="italic text-sm w-full" style={TRANSCRIBE_PULSE}>
+ <TranscribePulseKeyframes />
+ {t("settings.history.readingFile")}
+ </p>
+ </div>
+ );
+};
+
interface HeaderButtonProps {
onClick: () => void;
label: string;
@@ -90,6 +128,7 @@ export const HistorySettings: React.FC = () => {
const { t } = useTranslation();
const osType = useOsType();
const jobs = useTranscriptionJobsStore((state) => state.jobs);
+ const reads = useFileReadsStore((state) => state.reads);
const [entries, setEntries] = useState<HistoryEntry[]>([]);
const [loading, setLoading] = useState(true);
const [hasMore, setHasMore] = useState(true);
@@ -272,7 +311,7 @@ export const HistorySettings: React.FC = () => {
{t("settings.history.loading")}
</div>
);
- } else if (entries.length === 0) {
+ } else if (entries.length === 0 && reads.length === 0) {
content = (
<div className="px-4 py-3 text-center text-ink-2">
{t("settings.history.empty")}
@@ -283,6 +322,9 @@ export const HistorySettings: React.FC = () => {
<>
<AudioPlayerGroup>
<div className="divide-y divide-line">
+ {reads.map((read) => (
+ <FileReadRow key={`read-${read.id}`} read={read} />
+ ))}
{entries.map((entry) => (
<HistoryEntryComponent
key={entry.id}
@@ -504,7 +546,7 @@ const HistoryEntryComponent: React.FC<HistoryEntryProps> = ({
}`}
style={
retrying
- ? { animation: "transcribe-pulse 3s ease-in-out infinite" }
+ ? TRANSCRIBE_PULSE
: folded
? {
display: "-webkit-box",
@@ -515,14 +557,7 @@ const HistoryEntryComponent: React.FC<HistoryEntryProps> = ({
: undefined
}
>
- {retrying && (
- <style>{`
- @keyframes transcribe-pulse {
- 0%, 100% { color: var(--color-ink-3); }
- 50% { color: var(--color-text); }
- }
- `}</style>
- )}
+ {retrying && <TranscribePulseKeyframes />}
{retrying
? progressText
: hasTranscription
diff --git a/src/components/settings/history/transcribeFiles.ts b/src/components/settings/history/transcribeFiles.ts
index e4163d2d..875cb9b5 100644
--- a/src/components/settings/history/transcribeFiles.ts
+++ b/src/components/settings/history/transcribeFiles.ts
@@ -1,4 +1,5 @@
import { open } from "@tauri-apps/plugin-dialog";
+import { create } from "zustand";
import { notify } from "@/stores/noticeStore";
import i18n from "@/i18n";
import { commands } from "@/bindings";
@@ -21,13 +22,38 @@ const MEDIA_EXTENSIONS = [
const fileName = (path: string) => path.split(/[\\/]/).pop() || path;
+export interface FileRead {
+ id: number;
+ name: string;
+}
+
+// Files being read before they're added to History, newest first. A long
+// file takes a while to read, and History shows these in the meantime.
+export const useFileReadsStore = create<{ reads: FileRead[] }>()(() => ({
+ reads: [],
+}));
+
+let nextReadId = 0;
+
// Adds each file to History and queues it to be transcribed. Resolves to
// how many were added.
export const transcribeFiles = async (paths: string[]): Promise<number> => {
+ const reads = paths.map((path) => ({
+ id: nextReadId++,
+ name: fileName(path),
+ }));
+ // Reversed: each file lands in History above the one before it.
+ useFileReadsStore.setState((state) => ({
+ reads: [...[...reads].reverse(), ...state.reads],
+ }));
let added = 0;
- for (const path of paths) {
+ for (const [index, path] of paths.entries()) {
// Its audio is read in full before it appears in History.
- const result = await commands.transcribeFile(path);
+ const result = await commands.transcribeFile(path).finally(() => {
+ useFileReadsStore.setState((state) => ({
+ reads: state.reads.filter((read) => read.id !== reads[index].id),
+ }));
+ });
if (result.status === "ok") {
added += 1;
} else {
diff --git a/src/i18n/locales/ar/translation.json b/src/i18n/locales/ar/translation.json
index c0a9f876..2e4e71aa 100644
--- a/src/i18n/locales/ar/translation.json
+++ b/src/i18n/locales/ar/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "فشل النسخ. يرجى المحاولة مرة أخرى.",
"waiting": "في انتظار النسخ",
"transcribingPercent": "جارٍ النسخ، {{percent}}%",
+ "readingFile": "جارٍ قراءة الملف...",
"showMore": "عرض المزيد",
"showLess": "عرض أقل",
"dropTitle": "أفلت الملف لنسخه",
diff --git a/src/i18n/locales/bg/translation.json b/src/i18n/locales/bg/translation.json
index 932b6de7..1b09d404 100644
--- a/src/i18n/locales/bg/translation.json
+++ b/src/i18n/locales/bg/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "Транскрипцията не бе успешна. Моля, опитайте отново.",
"waiting": "Изчаква транскрибиране",
"transcribingPercent": "Транскрибиране, {{percent}}%",
+ "readingFile": "Четене на файла...",
"showMore": "Покажи повече",
"showLess": "Покажи по-малко",
"dropTitle": "Пуснете за транскрибиране",
diff --git a/src/i18n/locales/ca/translation.json b/src/i18n/locales/ca/translation.json
index 9e647cb0..28bfdc8b 100644
--- a/src/i18n/locales/ca/translation.json
+++ b/src/i18n/locales/ca/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "La transcripció ha fallat. Torna-ho a provar.",
"waiting": "Esperant per transcriure",
"transcribingPercent": "Transcrivint, {{percent}}%",
+ "readingFile": "S'està llegint el fitxer...",
"showMore": "Mostra'n més",
"showLess": "Mostra'n menys",
"dropTitle": "Deixa anar per transcriure",
diff --git a/src/i18n/locales/cs/translation.json b/src/i18n/locales/cs/translation.json
index 98b22ffa..48b6e118 100644
--- a/src/i18n/locales/cs/translation.json
+++ b/src/i18n/locales/cs/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "Přepis se nezdařil. Zkuste to prosím znovu.",
"waiting": "Čeká na přepis",
"transcribingPercent": "Přepisuji, {{percent}} %",
+ "readingFile": "Načítám soubor...",
"showMore": "Zobrazit více",
"showLess": "Zobrazit méně",
"dropTitle": "Pusťte pro přepis",
diff --git a/src/i18n/locales/da/translation.json b/src/i18n/locales/da/translation.json
index ee7ebac1..c79466a0 100644
--- a/src/i18n/locales/da/translation.json
+++ b/src/i18n/locales/da/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "Transskriptionen mislykkedes. Prøv igen.",
"waiting": "Venter på transskription",
"transcribingPercent": "Transskriberer, {{percent}} %",
+ "readingFile": "Læser fil...",
"showMore": "Vis mere",
"showLess": "Vis mindre",
"dropTitle": "Slip for at transskribere",
diff --git a/src/i18n/locales/de/translation.json b/src/i18n/locales/de/translation.json
index 28a26790..80854c43 100644
--- a/src/i18n/locales/de/translation.json
+++ b/src/i18n/locales/de/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "Transkription fehlgeschlagen. Bitte versuche es erneut.",
"waiting": "Wartet auf Transkription",
"transcribingPercent": "Transkribiere, {{percent}} %",
+ "readingFile": "Datei wird gelesen...",
"showMore": "Mehr anzeigen",
"showLess": "Weniger anzeigen",
"dropTitle": "Zum Transkribieren ablegen",
diff --git a/src/i18n/locales/en/translation.json b/src/i18n/locales/en/translation.json
index 7a33d78a..accadf2e 100644
--- a/src/i18n/locales/en/translation.json
+++ b/src/i18n/locales/en/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "Transcription failed. Please try again.",
"waiting": "Waiting to transcribe",
"transcribingPercent": "Transcribing, {{percent}}%",
+ "readingFile": "Reading file...",
"showMore": "Show more",
"showLess": "Show less",
"dropTitle": "Drop to transcribe",
diff --git a/src/i18n/locales/es/translation.json b/src/i18n/locales/es/translation.json
index 78f4427f..016dd7c1 100644
--- a/src/i18n/locales/es/translation.json
+++ b/src/i18n/locales/es/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "La transcripción falló. Inténtalo de nuevo.",
"waiting": "Esperando para transcribir",
"transcribingPercent": "Transcribiendo, {{percent}} %",
+ "readingFile": "Leyendo archivo...",
"showMore": "Mostrar más",
"showLess": "Mostrar menos",
"dropTitle": "Suelta para transcribir",
diff --git a/src/i18n/locales/fr/translation.json b/src/i18n/locales/fr/translation.json
index b26edfeb..4ba9e5ab 100644
--- a/src/i18n/locales/fr/translation.json
+++ b/src/i18n/locales/fr/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "La transcription a échoué. Veuillez réessayer.",
"waiting": "En attente de transcription",
"transcribingPercent": "Transcription, {{percent}} %",
+ "readingFile": "Lecture du fichier...",
"showMore": "Afficher plus",
"showLess": "Afficher moins",
"dropTitle": "Déposez pour transcrire",
diff --git a/src/i18n/locales/he/translation.json b/src/i18n/locales/he/translation.json
index 7964d344..4201f233 100644
--- a/src/i18n/locales/he/translation.json
+++ b/src/i18n/locales/he/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "התמלול נכשל. נסו שוב.",
"waiting": "ממתין לתמלול",
"transcribingPercent": "מתמלל, {{percent}}%",
+ "readingFile": "קורא קובץ...",
"showMore": "הצג עוד",
"showLess": "הצג פחות",
"dropTitle": "שחררו כדי לתמלל",
diff --git a/src/i18n/locales/hi/translation.json b/src/i18n/locales/hi/translation.json
index 70c2eca6..961dfd85 100644
--- a/src/i18n/locales/hi/translation.json
+++ b/src/i18n/locales/hi/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "ट्रांसक्रिप्शन विफल रहा। कृपया फिर से प्रयास करें।",
"waiting": "ट्रांसक्राइब होने की प्रतीक्षा में",
"transcribingPercent": "ट्रांसक्राइब हो रहा है, {{percent}}%",
+ "readingFile": "फ़ाइल पढ़ी जा रही है...",
"showMore": "और दिखाएँ",
"showLess": "कम दिखाएँ",
"dropTitle": "ट्रांसक्राइब करने के लिए छोड़ें",
diff --git a/src/i18n/locales/id/translation.json b/src/i18n/locales/id/translation.json
index 09a48513..644723ca 100644
--- a/src/i18n/locales/id/translation.json
+++ b/src/i18n/locales/id/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "Transkripsi gagal. Silakan coba lagi.",
"waiting": "Menunggu untuk ditranskripsi",
"transcribingPercent": "Mentranskripsi, {{percent}}%",
+ "readingFile": "Membaca file...",
"showMore": "Tampilkan lebih banyak",
"showLess": "Tampilkan lebih sedikit",
"dropTitle": "Lepaskan untuk mentranskripsi",
diff --git a/src/i18n/locales/it/translation.json b/src/i18n/locales/it/translation.json
index 6dcd02ec..b79f43eb 100644
--- a/src/i18n/locales/it/translation.json
+++ b/src/i18n/locales/it/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "Trascrizione non riuscita. Riprova.",
"waiting": "In attesa di trascrizione",
"transcribingPercent": "Trascrizione, {{percent}}%",
+ "readingFile": "Lettura del file in corso...",
"showMore": "Mostra di più",
"showLess": "Mostra di meno",
"dropTitle": "Rilascia per trascrivere",
diff --git a/src/i18n/locales/ja/translation.json b/src/i18n/locales/ja/translation.json
index 30c01b01..55ac4d0d 100644
--- a/src/i18n/locales/ja/translation.json
+++ b/src/i18n/locales/ja/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "文字起こしに失敗しました。もう一度お試しください。",
"waiting": "文字起こし待ち",
"transcribingPercent": "文字起こし中… {{percent}}%",
+ "readingFile": "ファイルを読み込み中…",
"showMore": "もっと見る",
"showLess": "閉じる",
"dropTitle": "ドロップして文字起こし",
diff --git a/src/i18n/locales/ko/translation.json b/src/i18n/locales/ko/translation.json
index a95220d6..f74eb3be 100644
--- a/src/i18n/locales/ko/translation.json
+++ b/src/i18n/locales/ko/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "받아쓰기에 실패했습니다. 다시 시도해 주세요.",
"waiting": "받아쓰기 대기 중",
"transcribingPercent": "받아쓰는 중, {{percent}}%",
+ "readingFile": "파일 읽는 중...",
"showMore": "더 보기",
"showLess": "간략히 보기",
"dropTitle": "놓아서 받아쓰기",
diff --git a/src/i18n/locales/ne/translation.json b/src/i18n/locales/ne/translation.json
index 24dc1a35..f02cce52 100644
--- a/src/i18n/locales/ne/translation.json
+++ b/src/i18n/locales/ne/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "ट्रान्सक्रिप्सन असफल भयो। कृपया फेरि प्रयास गर्नुहोस्।",
"waiting": "ट्रान्सक्राइब हुन पर्खँदै",
"transcribingPercent": "ट्रान्सक्राइब हुँदै, {{percent}}%",
+ "readingFile": "फाइल पढिँदैछ...",
"showMore": "थप देखाउनुहोस्",
"showLess": "कम देखाउनुहोस्",
"dropTitle": "ट्रान्सक्राइब गर्न छोड्नुहोस्",
diff --git a/src/i18n/locales/nl/translation.json b/src/i18n/locales/nl/translation.json
index 538ec8f6..00803305 100644
--- a/src/i18n/locales/nl/translation.json
+++ b/src/i18n/locales/nl/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "Transcriptie mislukt. Probeer het opnieuw.",
"waiting": "Wacht op transcriptie",
"transcribingPercent": "Transcriberen, {{percent}}%",
+ "readingFile": "Bestand lezen...",
"showMore": "Meer tonen",
"showLess": "Minder tonen",
"dropTitle": "Loslaten om te transcriberen",
diff --git a/src/i18n/locales/pl/translation.json b/src/i18n/locales/pl/translation.json
index f9f6c857..aa8fada0 100644
--- a/src/i18n/locales/pl/translation.json
+++ b/src/i18n/locales/pl/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "Transkrypcja nie powiodła się. Spróbuj ponownie.",
"waiting": "Oczekuje na transkrypcję",
"transcribingPercent": "Transkrypcja, {{percent}}%",
+ "readingFile": "Odczytuję plik...",
"showMore": "Pokaż więcej",
"showLess": "Pokaż mniej",
"dropTitle": "Upuść, aby transkrybować",
diff --git a/src/i18n/locales/pt/translation.json b/src/i18n/locales/pt/translation.json
index 173c2a71..235495bf 100644
--- a/src/i18n/locales/pt/translation.json
+++ b/src/i18n/locales/pt/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "A transcrição falhou. Tente novamente.",
"waiting": "Aguardando transcrição",
"transcribingPercent": "Transcrevendo, {{percent}}%",
+ "readingFile": "Lendo arquivo...",
"showMore": "Mostrar mais",
"showLess": "Mostrar menos",
"dropTitle": "Solte para transcrever",
diff --git a/src/i18n/locales/ru/translation.json b/src/i18n/locales/ru/translation.json
index 7919e818..47d0ca0c 100644
--- a/src/i18n/locales/ru/translation.json
+++ b/src/i18n/locales/ru/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "Не удалось выполнить расшифровку. Попробуйте ещё раз.",
"waiting": "Ожидает расшифровки",
"transcribingPercent": "Расшифровка, {{percent}}%",
+ "readingFile": "Чтение файла...",
"showMore": "Показать больше",
"showLess": "Показать меньше",
"dropTitle": "Отпустите, чтобы расшифровать",
diff --git a/src/i18n/locales/sv/translation.json b/src/i18n/locales/sv/translation.json
index f5288674..ae6cf3e0 100644
--- a/src/i18n/locales/sv/translation.json
+++ b/src/i18n/locales/sv/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "Transkriberingen misslyckades. Försök igen.",
"waiting": "Väntar på transkribering",
"transcribingPercent": "Transkriberar, {{percent}} %",
+ "readingFile": "Läser fil...",
"showMore": "Visa mer",
"showLess": "Visa mindre",
"dropTitle": "Släpp för att transkribera",
diff --git a/src/i18n/locales/tr/translation.json b/src/i18n/locales/tr/translation.json
index e3bbd5ce..d60bfdb3 100644
--- a/src/i18n/locales/tr/translation.json
+++ b/src/i18n/locales/tr/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "Yazıya dökme başarısız oldu. Lütfen tekrar deneyin.",
"waiting": "Yazıya dökülmeyi bekliyor",
"transcribingPercent": "Yazıya dökülüyor, %{{percent}}",
+ "readingFile": "Dosya okunuyor...",
"showMore": "Daha fazla göster",
"showLess": "Daha az göster",
"dropTitle": "Yazıya dökmek için bırakın",
diff --git a/src/i18n/locales/uk/translation.json b/src/i18n/locales/uk/translation.json
index 64bbb7a1..00e42a1f 100644
--- a/src/i18n/locales/uk/translation.json
+++ b/src/i18n/locales/uk/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "Не вдалося розшифрувати. Спробуйте ще раз.",
"waiting": "Очікує на розшифрування",
"transcribingPercent": "Розшифрування, {{percent}}%",
+ "readingFile": "Читання файлу...",
"showMore": "Показати більше",
"showLess": "Показати менше",
"dropTitle": "Відпустіть, щоб розшифрувати",
diff --git a/src/i18n/locales/vi/translation.json b/src/i18n/locales/vi/translation.json
index fd5fa1f6..5b8a741b 100644
--- a/src/i18n/locales/vi/translation.json
+++ b/src/i18n/locales/vi/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "Chép lời thất bại. Vui lòng thử lại.",
"waiting": "Đang chờ chép lời",
"transcribingPercent": "Đang chép lời, {{percent}}%",
+ "readingFile": "Đang đọc tệp...",
"showMore": "Xem thêm",
"showLess": "Thu gọn",
"dropTitle": "Thả để chép lời",
diff --git a/src/i18n/locales/zh-TW/translation.json b/src/i18n/locales/zh-TW/translation.json
index 6a6f58cf..012c0ca0 100644
--- a/src/i18n/locales/zh-TW/translation.json
+++ b/src/i18n/locales/zh-TW/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "轉錄失敗,請重試。",
"waiting": "等待轉錄",
"transcribingPercent": "正在轉錄,{{percent}}%",
+ "readingFile": "正在讀取檔案...",
"showMore": "顯示更多",
"showLess": "收合",
"dropTitle": "拖放到此處進行轉錄",
diff --git a/src/i18n/locales/zh/translation.json b/src/i18n/locales/zh/translation.json
index e76b351e..e7890b1c 100644
--- a/src/i18n/locales/zh/translation.json
+++ b/src/i18n/locales/zh/translation.json
@@ -709,6 +709,7 @@
"transcribeFailed": "转录失败,请重试。",
"waiting": "等待转录",
"transcribingPercent": "正在转录,{{percent}}%",
+ "readingFile": "正在读取文件...",
"showMore": "显示更多",
"showLess": "收起",
"dropTitle": "拖放到此处进行转录",