From 73bb3e765ac49a4ce6e7d8c8ed5b669aa13d9470 Mon Sep 17 00:00:00 2001 From: Beingpax Date: Sat, 23 Aug 2025 22:15:13 +0545 Subject: [PATCH] Remove dictionary item dependency on local Whisper model --- VoiceInk/Services/ImportExportService.swift | 4 +- .../Views/Dictionary/DictionaryView.swift | 8 ---- VoiceInk/Whisper/WhisperPrompt.swift | 38 +------------------ 3 files changed, 4 insertions(+), 46 deletions(-) diff --git a/VoiceInk/Services/ImportExportService.swift b/VoiceInk/Services/ImportExportService.swift index 70735cd..2b08313 100644 --- a/VoiceInk/Services/ImportExportService.swift +++ b/VoiceInk/Services/ImportExportService.swift @@ -198,8 +198,8 @@ class ImportExportService { } if let itemsToImport = importedSettings.dictionaryItems { - Task { - await whisperPrompt.saveDictionaryItems(itemsToImport) + if let encoded = try? JSONEncoder().encode(itemsToImport) { + UserDefaults.standard.set(encoded, forKey: "CustomDictionaryItems") } } else { print("No dictionary items (for spelling) found in the imported file. Existing items remain unchanged.") diff --git a/VoiceInk/Views/Dictionary/DictionaryView.swift b/VoiceInk/Views/Dictionary/DictionaryView.swift index 5832b20..845ada4 100644 --- a/VoiceInk/Views/Dictionary/DictionaryView.swift +++ b/VoiceInk/Views/Dictionary/DictionaryView.swift @@ -29,20 +29,12 @@ class DictionaryManager: ObservableObject { if let savedItems = try? JSONDecoder().decode([DictionaryItem].self, from: data) { items = savedItems.sorted(by: { $0.dateAdded > $1.dateAdded }) - updatePrompt() } } private func saveItems() { if let encoded = try? JSONEncoder().encode(items) { UserDefaults.standard.set(encoded, forKey: saveKey) - updatePrompt() - } - } - - private func updatePrompt() { - Task { @MainActor in - await whisperPrompt.saveDictionaryItems(items) } } diff --git a/VoiceInk/Whisper/WhisperPrompt.swift b/VoiceInk/Whisper/WhisperPrompt.swift index c865845..bf62c79 100644 --- a/VoiceInk/Whisper/WhisperPrompt.swift +++ b/VoiceInk/Whisper/WhisperPrompt.swift @@ -5,8 +5,6 @@ import Foundation class WhisperPrompt: ObservableObject { @Published var transcriptionPrompt: String = UserDefaults.standard.string(forKey: "TranscriptionPrompt") ?? "" - private var dictionaryWords: [String] = [] - private let saveKey = "CustomDictionaryItems" private let customPromptsKey = "CustomLanguagePrompts" // Store user-customized prompts @@ -55,7 +53,6 @@ class WhisperPrompt: ObservableObject { ] init() { - loadDictionaryItems() loadCustomPrompts() updateTranscriptionPrompt() @@ -76,16 +73,6 @@ class WhisperPrompt: ObservableObject { updateTranscriptionPrompt() } - private func loadDictionaryItems() { - guard let data = UserDefaults.standard.data(forKey: saveKey) else { return } - - if let savedItems = try? JSONDecoder().decode([DictionaryItem].self, from: data) { - let enabledWords = savedItems.filter { $0.isEnabled }.map { $0.word } - dictionaryWords = enabledWords - updateTranscriptionPrompt() - } - } - private func loadCustomPrompts() { if let savedPrompts = UserDefaults.standard.dictionary(forKey: customPromptsKey) as? [String: String] { customPrompts = savedPrompts @@ -97,25 +84,13 @@ class WhisperPrompt: ObservableObject { UserDefaults.standard.synchronize() // Force immediate synchronization } - func updateDictionaryWords(_ words: [String]) { - dictionaryWords = words - updateTranscriptionPrompt() - } - func updateTranscriptionPrompt() { // Get the currently selected language from UserDefaults let selectedLanguage = UserDefaults.standard.string(forKey: "SelectedLanguage") ?? "en" // Get the prompt for the selected language (custom if available, otherwise default) let basePrompt = getLanguagePrompt(for: selectedLanguage) - - // Always include VoiceInk in the prompt - var prompt = basePrompt + "\nVoiceInk, " - - // Add dictionary words if available - if !dictionaryWords.isEmpty { - prompt += dictionaryWords.joined(separator: ", ") - } + let prompt = basePrompt.isEmpty ? "" : basePrompt transcriptionPrompt = prompt UserDefaults.standard.set(prompt, forKey: "TranscriptionPrompt") @@ -143,13 +118,4 @@ class WhisperPrompt: ObservableObject { // Force update the UI objectWillChange.send() } - - func saveDictionaryItems(_ items: [DictionaryItem]) async { - if let encoded = try? JSONEncoder().encode(items) { - UserDefaults.standard.set(encoded, forKey: saveKey) - let enabledWords = items.filter { $0.isEnabled }.map { $0.word } - dictionaryWords = enabledWords - updateTranscriptionPrompt() - } - } -} +}