From 5eacee467a3f87fce02bfac5dca2a0a9dd40158b Mon Sep 17 00:00:00 2001 From: Beingpax Date: Sat, 6 Sep 2025 08:57:32 +0545 Subject: [PATCH] Feat: Respect VAD user setting in ParakeetTranscriptionService --- .../ParakeetTranscriptionService.swift | 47 +++++++++++-------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/VoiceInk/Services/ParakeetTranscriptionService.swift b/VoiceInk/Services/ParakeetTranscriptionService.swift index 1d60491..da2d092 100644 --- a/VoiceInk/Services/ParakeetTranscriptionService.swift +++ b/VoiceInk/Services/ParakeetTranscriptionService.swift @@ -79,34 +79,41 @@ class ParakeetTranscriptionService: TranscriptionService { // Use VAD to get speech segments var speechAudio: [Float] = [] - if let modelPath = await VADModelManager.shared.getModelPath() { - if let vad = VoiceActivityDetector(modelPath: modelPath) { - let speechSegments = vad.process(audioSamples: audioSamples) - logger.notice("🦜 VAD detected \(speechSegments.count) speech segments.") + let isVADEnabled = UserDefaults.standard.object(forKey: "IsVADEnabled") as? Bool ?? true - let sampleRate = 16000 // Assuming 16kHz sample rate - for segment in speechSegments { - let startSample = Int(segment.start * Double(sampleRate)) - var endSample = Int(segment.end * Double(sampleRate)) + if isVADEnabled { + if let modelPath = await VADModelManager.shared.getModelPath() { + if let vad = VoiceActivityDetector(modelPath: modelPath) { + let speechSegments = vad.process(audioSamples: audioSamples) + logger.notice("🦜 VAD detected \(speechSegments.count) speech segments.") - // Cap endSample to the audio buffer size - if endSample > audioSamples.count { - endSample = audioSamples.count - } - - if startSample < endSample { - speechAudio.append(contentsOf: audioSamples[startSample.. audioSamples.count { + endSample = audioSamples.count + } + + if startSample < endSample { + speechAudio.append(contentsOf: audioSamples[startSample..