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.
This commit is contained in:
parent
0faffa0155
commit
78dcc0dfa4
@ -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
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user