A free, open source, and extensible speech-to-text application that works completely offline.
fix(custom-words): allow multi-word phrases (#1406)
Max2cf157d96290
diff --git a/src-tauri/src/audio_toolkit/text.rs b/src-tauri/src/audio_toolkit/text.rsindex b212301e..82d45b5a 100644--- a/src-tauri/src/audio_toolkit/text.rs+++ b/src-tauri/src/audio_toolkit/text.rs@@ -768,7 +768,7 @@ mod tests {let text = "using Mac Book Pro";let custom_words = vec!["MacBook Pro".to_string()];let result = apply_custom_words(text, &custom_words, 0.5);- assert!(result.contains("MacBook"));+ assert_eq!(result, "using MacBook Pro");}#[test]diff --git a/src/components/settings/CustomWords.tsx b/src/components/settings/CustomWords.tsxindex 4731becb..211e9828 100644--- a/src/components/settings/CustomWords.tsx+++ b/src/components/settings/CustomWords.tsx@@ -11,30 +11,31 @@ interface CustomWordsProps {grouped?: boolean;}+const normalizeCustomWord = (word: string) =>+ word+ .replace(/[<>"']/g, "")+ .replace(/\s+/g, " ")+ .trim();+export const CustomWords: React.FC<CustomWordsProps> = React.memo(({ descriptionMode = "tooltip", grouped = false }) => {const { t } = useTranslation();const { getSetting, updateSetting, isUpdating } = useSettings();const [newWord, setNewWord] = useState("");const customWords = getSetting("custom_words") || [];+ const normalizedWord = normalizeCustomWord(newWord);const handleAddWord = () => {- const trimmedWord = newWord.trim();- const sanitizedWord = trimmedWord.replace(/[<>"']/g, "");- if (- sanitizedWord &&- !sanitizedWord.includes(" ") &&- sanitizedWord.length <= 50- ) {- if (customWords.includes(sanitizedWord)) {+ if (normalizedWord && normalizedWord.length <= 50) {+ if (customWords.includes(normalizedWord)) {toast.error(t("settings.advanced.customWords.duplicate", {- word: sanitizedWord,+ word: normalizedWord,}),);return;}- updateSetting("custom_words", [...customWords, sanitizedWord]);+ updateSetting("custom_words", [...customWords, normalizedWord]);setNewWord("");}};@@ -75,9 +76,8 @@ export const CustomWords: React.FC<CustomWordsProps> = React.memo(<ButtononClick={handleAddWord}disabled={- !newWord.trim() ||- newWord.includes(" ") ||- newWord.trim().length > 50 ||+ !normalizedWord ||+ normalizedWord.length > 50 ||isUpdating("custom_words")}variant="primary"