From 87593ac243e33f26fb2ec45a580beeb2ea8387e3 Mon Sep 17 00:00:00 2001 From: Beingpax Date: Thu, 14 Aug 2025 19:54:19 +0545 Subject: [PATCH] Fix AVFoundation failing to get the audio duration --- VoiceInk/Whisper/WhisperState.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/VoiceInk/Whisper/WhisperState.swift b/VoiceInk/Whisper/WhisperState.swift index 5f0399f..627d1b1 100644 --- a/VoiceInk/Whisper/WhisperState.swift +++ b/VoiceInk/Whisper/WhisperState.swift @@ -279,7 +279,7 @@ class WhisperState: NSObject, ObservableObject { } let audioAsset = AVURLAsset(url: url) - let actualDuration = CMTimeGetSeconds(try await audioAsset.load(.duration)) + let actualDuration = (try? CMTimeGetSeconds(await audioAsset.load(.duration))) ?? 0.0 var promptDetectionResult: PromptDetectionService.PromptDetectionResult? = nil let originalText = text @@ -380,7 +380,7 @@ class WhisperState: NSObject, ObservableObject { } catch { do { let audioAsset = AVURLAsset(url: url) - let duration = CMTimeGetSeconds(try await audioAsset.load(.duration)) + let duration = (try? CMTimeGetSeconds(await audioAsset.load(.duration))) ?? 0.0 await MainActor.run { let errorDescription = (error as? LocalizedError)?.errorDescription ?? error.localizedDescription