From 78dcc0dfa49522d25eb0579d503688552fd373fb Mon Sep 17 00:00:00 2001 From: slumdev88 Date: Fri, 4 Jul 2025 21:55:09 +0800 Subject: [PATCH] Fix SpeechTranscriber API compatibility with older Xcode versions Add conditional compilation directives to wrap SpeechTranscriber usage which is only available in macOS 26/Xcode 16+. This prevents build failures on current Xcode versions while maintaining future compatibility. --- .../Services/NativeAppleTranscriptionService.swift | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/VoiceInk/Services/NativeAppleTranscriptionService.swift b/VoiceInk/Services/NativeAppleTranscriptionService.swift index 2ed95bc..06754ca 100644 --- a/VoiceInk/Services/NativeAppleTranscriptionService.swift +++ b/VoiceInk/Services/NativeAppleTranscriptionService.swift @@ -62,7 +62,7 @@ class NativeAppleTranscriptionService: TranscriptionService { throw ServiceError.unsupportedOS } - #if canImport(Speech) + #if canImport(Speech) && compiler(>=6.0) && swift(>=6.0) logger.notice("Starting Apple native transcription with SpeechAnalyzer.") let audioFile = try AVAudioFile(forReading: audioURL) @@ -143,11 +143,12 @@ class NativeAppleTranscriptionService: TranscriptionService { return finalTranscription #else - logger.error("Speech framework is not available") + logger.error("SpeechTranscriber is not available in this compiler version or Speech framework is not available") throw ServiceError.unsupportedOS #endif } + #if compiler(>=6.0) && swift(>=6.0) @available(macOS 26, *) private func deallocateExistingAssets() async throws { #if canImport(Speech) @@ -158,7 +159,9 @@ class NativeAppleTranscriptionService: TranscriptionService { logger.notice("Deallocated existing asset locales.") #endif } + #endif + #if compiler(>=6.0) && swift(>=6.0) @available(macOS 26, *) private func allocateAssetsForLocale(_ locale: Locale) async throws { #if canImport(Speech) @@ -171,7 +174,9 @@ class NativeAppleTranscriptionService: TranscriptionService { } #endif } + #endif + #if compiler(>=6.0) && swift(>=6.0) @available(macOS 26, *) private func ensureModelIsAvailable(for transcriber: SpeechTranscriber, locale: Locale) async throws { #if canImport(Speech) @@ -191,4 +196,5 @@ class NativeAppleTranscriptionService: TranscriptionService { } #endif } + #endif }