Skip to content

Commit

Permalink
Merge pull request #25 from exPHAT/enhanced_platform_support
Browse files Browse the repository at this point in the history
  • Loading branch information
exPHAT authored Aug 17, 2023
2 parents 54322da + 21a2720 commit a192004
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions Sources/SwiftWhisper/Whisper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions Tests/WhisperTests/File Tests/ModelFileTestCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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")!
Expand Down
4 changes: 2 additions & 2 deletions Tests/WhisperTests/Model Tests/LoadModelTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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!
Expand All @@ -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!
Expand Down Expand Up @@ -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!
Expand Down Expand Up @@ -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

Expand All @@ -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!
Expand Down Expand Up @@ -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!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 5 additions & 5 deletions Tests/WhisperTests/Transcription Tests/TranscriptionTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand All @@ -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!
Expand All @@ -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!
Expand Down Expand Up @@ -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

Expand All @@ -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!
Expand Down

0 comments on commit a192004

Please sign in to comment.