From b5eaf647db22ed26ba928012d92005071987e31f Mon Sep 17 00:00:00 2001 From: Beingpax Date: Sat, 2 Aug 2025 21:26:37 +0545 Subject: [PATCH] =?UTF-8?q?=F0=9F=A6=9C=20Add=20Parakeet=20logging?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ParakeetTranscriptionService.swift | 53 +++++++++++++------ 1 file changed, 37 insertions(+), 16 deletions(-) diff --git a/VoiceInk/Services/ParakeetTranscriptionService.swift b/VoiceInk/Services/ParakeetTranscriptionService.swift index 15566c7..6428782 100644 --- a/VoiceInk/Services/ParakeetTranscriptionService.swift +++ b/VoiceInk/Services/ParakeetTranscriptionService.swift @@ -1,6 +1,7 @@ import Foundation import AVFoundation import FluidAudio +import os.log @@ -9,6 +10,9 @@ class ParakeetTranscriptionService: TranscriptionService { private let customModelsDirectory: URL? @Published var isModelLoaded = false + // Logger for Parakeet transcription service + private let logger = Logger(subsystem: "com.voiceink.app", category: "ParakeetTranscriptionService") + init(customModelsDirectory: URL? = nil) { self.customModelsDirectory = customModelsDirectory } @@ -18,24 +22,37 @@ class ParakeetTranscriptionService: TranscriptionService { return } - let asrConfig = ASRConfig( - maxSymbolsPerFrame: 3, - realtimeMode: true, - chunkSizeMs: 1500, - tdtConfig: TdtConfig( - durations: [0, 1, 2, 3, 4], - maxSymbolsPerStep: 3 + logger.notice("🦜 Starting Parakeet model loading") + + do { + let asrConfig = ASRConfig( + maxSymbolsPerFrame: 3, + realtimeMode: true, + chunkSizeMs: 1500, + tdtConfig: TdtConfig( + durations: [0, 1, 2, 3, 4], + maxSymbolsPerStep: 3 + ) ) - ) - asrManager = AsrManager(config: asrConfig) - let models: AsrModels - if let customDirectory = customModelsDirectory { - models = try await AsrModels.downloadAndLoad(to: customDirectory) - } else { - models = try await AsrModels.downloadAndLoad() + asrManager = AsrManager(config: asrConfig) + + let models: AsrModels + if let customDirectory = customModelsDirectory { + models = try await AsrModels.downloadAndLoad(to: customDirectory) + } else { + models = try await AsrModels.downloadAndLoad() + } + + try await asrManager?.initialize(models: models) + isModelLoaded = true + logger.notice("🦜 Parakeet model loaded successfully") + + } catch { + logger.error("🦜 Failed to load Parakeet model: \(error.localizedDescription)") + isModelLoaded = false + asrManager = nil + throw error } - try await asrManager?.initialize(models: models) - isModelLoaded = true } func transcribe(audioURL: URL, model: any TranscriptionModel) async throws -> String { @@ -51,17 +68,21 @@ class ParakeetTranscriptionService: TranscriptionService { } guard let asrManager = asrManager else { + logger.error("🦜 ASR manager is nil after model loading") throw NSError(domain: "ParakeetTranscriptionService", code: -1, userInfo: [NSLocalizedDescriptionKey: "Failed to initialize ASR manager."]) } + logger.notice("🦜 Starting Parakeet transcription") let audioSamples = try readAudioSamples(from: audioURL) let result = try await asrManager.transcribe(audioSamples) + logger.notice("🦜 Parakeet transcription completed") if UserDefaults.standard.object(forKey: "IsTextFormattingEnabled") as? Bool ?? true { return WhisperTextFormatter.format(result.text) } return result.text } catch { + logger.error("🦜 Parakeet transcription failed: \(error.localizedDescription)") let errorMessage = error.localizedDescription await MainActor.run { NotificationManager.shared.showNotification(