From 21a2720451c4b1218ef1747b44ccd7dccb45085c Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Thu, 17 Aug 2023 11:45:27 -0400 Subject: [PATCH] tvOS support --- Sources/SwiftWhisper/Whisper.swift | 4 ++-- .../File Tests/ModelFileTestCase.swift | 4 ++-- .../WhisperTests/Model Tests/LoadModelTests.swift | 4 ++-- .../TranscriptionCancellationTests.swift | 14 +++++++------- .../TranscriptionParameterTests.swift | 2 +- .../Transcription Tests/TranscriptionTests.swift | 10 +++++----- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/Sources/SwiftWhisper/Whisper.swift b/Sources/SwiftWhisper/Whisper.swift index 6c8df4b..dfbea17 100644 --- a/Sources/SwiftWhisper/Whisper.swift +++ b/Sources/SwiftWhisper/Whisper.swift @@ -175,7 +175,7 @@ public class Whisper { cancelCallback = completionHandler } - @available(iOS 13, macOS 10.15, watchOS 6.0, *) + @available(iOS 13, macOS 10.15, watchOS 6.0, tvOS 13.0, *) public func transcribe(audioFrames: [Float]) async throws -> [Segment] { return try await withCheckedThrowingContinuation { cont in self.transcribe(audioFrames: audioFrames) { result in @@ -189,7 +189,7 @@ public class Whisper { } } - @available(iOS 13, macOS 10.15, watchOS 6.0, *) + @available(iOS 13, macOS 10.15, watchOS 6.0, tvOS 13.0, *) public func cancel() async throws { return try await withCheckedThrowingContinuation { cont in do { diff --git a/Tests/WhisperTests/File Tests/ModelFileTestCase.swift b/Tests/WhisperTests/File Tests/ModelFileTestCase.swift index 3fac16b..6be31ef 100644 --- a/Tests/WhisperTests/File Tests/ModelFileTestCase.swift +++ b/Tests/WhisperTests/File Tests/ModelFileTestCase.swift @@ -6,12 +6,12 @@ import FoundationNetworking #endif protocol ModelFileTestCase: ResourceDependentTestCase { - @available(iOS 13, macOS 10.15, watchOS 6.0, *) + @available(iOS 13, macOS 10.15, watchOS 6.0, tvOS 13.0, *) var tinyModelURL: URL? { get async } } extension ModelFileTestCase { - @available(iOS 13, macOS 10.15, watchOS 6.0, *) + @available(iOS 13, macOS 10.15, watchOS 6.0, tvOS 13.0, *) var tinyModelURL: URL? { get async { let hostedModelURL = URL(string: "https://huggingface.co/ggerganov/whisper.cpp/resolve/main/ggml-tiny.bin")! diff --git a/Tests/WhisperTests/Model Tests/LoadModelTests.swift b/Tests/WhisperTests/Model Tests/LoadModelTests.swift index bc73622..a1a71a8 100644 --- a/Tests/WhisperTests/Model Tests/LoadModelTests.swift +++ b/Tests/WhisperTests/Model Tests/LoadModelTests.swift @@ -3,13 +3,13 @@ import XCTest @testable import SwiftWhisper class LoadModelTests: ResourceDependentTestCase, ModelFileTestCase { - @available(iOS 13, macOS 10.15, watchOS 6.0, *) + @available(iOS 13, macOS 10.15, watchOS 6.0, tvOS 13.0, *) func testLoadModelFromFile() async { let modelURL = await tinyModelURL! let _ = Whisper(fromFileURL: modelURL) } - @available(iOS 13, macOS 10.15, watchOS 6.0, *) + @available(iOS 13, macOS 10.15, watchOS 6.0, tvOS 13.0, *) func testLoadModelFromData() async throws { let modelURL = await tinyModelURL! let modelData = try Data(contentsOf: modelURL) diff --git a/Tests/WhisperTests/Transcription Tests/TranscriptionCancellationTests.swift b/Tests/WhisperTests/Transcription Tests/TranscriptionCancellationTests.swift index b74f01c..b7cd87f 100644 --- a/Tests/WhisperTests/Transcription Tests/TranscriptionCancellationTests.swift +++ b/Tests/WhisperTests/Transcription Tests/TranscriptionCancellationTests.swift @@ -5,7 +5,7 @@ import XCTest class TranscriptionCancellationTests: ResourceDependentTestCase, ModelFileTestCase, AudioFileTestCase { let timeout: TimeInterval = 60 - @available(iOS 13, macOS 10.15, watchOS 6.0, *) + @available(iOS 13, macOS 10.15, watchOS 6.0, tvOS 13.0, *) fileprivate var whisperTinyModel: Whisper { get async { let modelURL = await tinyModelURL! @@ -15,7 +15,7 @@ class TranscriptionCancellationTests: ResourceDependentTestCase, ModelFileTestCa } } - @available(iOS 13, macOS 10.15, watchOS 6.0, *) + @available(iOS 13, macOS 10.15, watchOS 6.0, tvOS 13.0, *) func testTranscribeCancellation() async { let whisper = await whisperTinyModel let jfk = jfkAudioFrames! @@ -42,7 +42,7 @@ class TranscriptionCancellationTests: ResourceDependentTestCase, ModelFileTestCa wait(for: [cancelExpectation, failureExpectation], timeout: timeout) } - @available(iOS 13, macOS 10.15, watchOS 6.0, *) + @available(iOS 13, macOS 10.15, watchOS 6.0, tvOS 13.0, *) func testTranscribeCancellationRestart() async { let whisper = await whisperTinyModel let jfk = jfkAudioFrames! @@ -80,7 +80,7 @@ class TranscriptionCancellationTests: ResourceDependentTestCase, ModelFileTestCa wait(for: [cancelExpectation, failureExpectation, restartExpectation], timeout: timeout) } - @available(iOS 13, macOS 10.15, watchOS 6.0, *) + @available(iOS 13, macOS 10.15, watchOS 6.0, tvOS 13.0, *) func testTranscribeDoubleCancellation() async { let whisper = await whisperTinyModel let jfk = jfkAudioFrames! @@ -113,7 +113,7 @@ class TranscriptionCancellationTests: ResourceDependentTestCase, ModelFileTestCa wait(for: [cancelExpectation, failureExpectation], timeout: timeout) } - @available(iOS 13, macOS 10.15, watchOS 6.0, *) + @available(iOS 13, macOS 10.15, watchOS 6.0, tvOS 13.0, *) func testTranscribePrematureCancellation() async { let whisper = await whisperTinyModel @@ -128,7 +128,7 @@ class TranscriptionCancellationTests: ResourceDependentTestCase, ModelFileTestCa } } - @available(iOS 13, macOS 10.15, watchOS 6.0, *) + @available(iOS 13, macOS 10.15, watchOS 6.0, tvOS 13.0, *) func testTranscriptionAsyncCancel() async { let whisper = await whisperTinyModel let jfk = jfkAudioFrames! @@ -159,7 +159,7 @@ class TranscriptionCancellationTests: ResourceDependentTestCase, ModelFileTestCa } - @available(iOS 13, macOS 10.15, watchOS 6.0, *) + @available(iOS 13, macOS 10.15, watchOS 6.0, tvOS 13.0, *) func testTranscriptionAsyncCancelTwice() async { let whisper = await whisperTinyModel let jfk = jfkAudioFrames! diff --git a/Tests/WhisperTests/Transcription Tests/TranscriptionParameterTests.swift b/Tests/WhisperTests/Transcription Tests/TranscriptionParameterTests.swift index 7eb5af2..d653c28 100644 --- a/Tests/WhisperTests/Transcription Tests/TranscriptionParameterTests.swift +++ b/Tests/WhisperTests/Transcription Tests/TranscriptionParameterTests.swift @@ -4,7 +4,7 @@ import XCTest class TranscriptionParamterTests: ResourceDependentTestCase, ModelFileTestCase, AudioFileTestCase { let timeout: TimeInterval = 60 - @available(iOS 13, macOS 10.15, watchOS 6.0, *) + @available(iOS 13, macOS 10.15, watchOS 6.0, tvOS 13.0, *) func testParametersMaxLen() async throws { let params = WhisperParams() params.language = .english diff --git a/Tests/WhisperTests/Transcription Tests/TranscriptionTests.swift b/Tests/WhisperTests/Transcription Tests/TranscriptionTests.swift index fbe9b17..ba558f5 100644 --- a/Tests/WhisperTests/Transcription Tests/TranscriptionTests.swift +++ b/Tests/WhisperTests/Transcription Tests/TranscriptionTests.swift @@ -4,7 +4,7 @@ import XCTest class TranscriptionTests: ResourceDependentTestCase, ModelFileTestCase, AudioFileTestCase { let timeout: TimeInterval = 60 - @available(iOS 13, macOS 10.15, watchOS 6.0, *) + @available(iOS 13, macOS 10.15, watchOS 6.0, tvOS 13.0, *) fileprivate var whisperTinyModel: Whisper { get async { let modelURL = await tinyModelURL! @@ -14,7 +14,7 @@ class TranscriptionTests: ResourceDependentTestCase, ModelFileTestCase, AudioFil } } - @available(iOS 13, macOS 10.15, watchOS 6.0, *) + @available(iOS 13, macOS 10.15, watchOS 6.0, tvOS 13.0, *) func testTrascribeCompletionHandler() async { let whisper = await whisperTinyModel let jfk = jfkAudioFrames! @@ -34,7 +34,7 @@ class TranscriptionTests: ResourceDependentTestCase, ModelFileTestCase, AudioFil wait(for: [successExpectation], timeout: timeout) } - @available(iOS 13, macOS 10.15, watchOS 6.0, *) + @available(iOS 13, macOS 10.15, watchOS 6.0, tvOS 13.0, *) func testTranscribeExclusivity() async { let whisper = await whisperTinyModel let jfk = jfkAudioFrames! @@ -65,7 +65,7 @@ class TranscriptionTests: ResourceDependentTestCase, ModelFileTestCase, AudioFil wait(for: [successExpectation, failureExpectation], timeout: timeout) } - @available(iOS 13, macOS 10.15, watchOS 6.0, *) + @available(iOS 13, macOS 10.15, watchOS 6.0, tvOS 13.0, *) func testTranscribeInvalidFramesError() async { let whisper = await whisperTinyModel @@ -91,7 +91,7 @@ class TranscriptionTests: ResourceDependentTestCase, ModelFileTestCase, AudioFil } extension TranscriptionTests: WhisperDelegate { - @available(iOS 13, macOS 10.15, watchOS 6.0, *) + @available(iOS 13, macOS 10.15, watchOS 6.0, tvOS 13.0, *) func testTranscribeDelegate() async throws { let whisper = await whisperTinyModel let jfk = jfkAudioFrames!