diff --git a/Sources/ExyteOpenAI/OpenAI+Audio.swift b/Sources/ExyteOpenAI/OpenAI+Audio.swift index ed90c86..be97afb 100644 --- a/Sources/ExyteOpenAI/OpenAI+Audio.swift +++ b/Sources/ExyteOpenAI/OpenAI+Audio.swift @@ -41,6 +41,20 @@ public extension OpenAI { .eraseToAnyPublisher() } + func createTranscription(from payload: CreateTranscriptionPayload) -> AnyPublisher { + audioProvider.requestPublisher(for: .createTranscription(payload: payload)) + .flatMap { + guard let stringData = String(data: $0.data, encoding: .utf8) else { + return Fail(error: .requestCreationFailed) + .eraseToAnyPublisher() + } + return Just(stringData) + .setFailureType(to: OpenAIError.self) + .eraseToAnyPublisher() + } + .eraseToAnyPublisher() + } + func createTranslation(from payload: CreateTranslationPayload) -> AnyPublisher { audioProvider.requestPublisher(for: .createTranslation(payload: payload)) .map { $0.data } @@ -48,6 +62,20 @@ public extension OpenAI { .eraseToAnyPublisher() } + func createTranslation(from payload: CreateTranslationPayload) -> AnyPublisher { + audioProvider.requestPublisher(for: .createTranslation(payload: payload)) + .flatMap { + guard let stringData = String(data: $0.data, encoding: .utf8) else { + return Fail(error: .requestCreationFailed) + .eraseToAnyPublisher() + } + return Just(stringData) + .setFailureType(to: OpenAIError.self) + .eraseToAnyPublisher() + } + .eraseToAnyPublisher() + } + } // MARK: - Concurrency @@ -62,8 +90,16 @@ public extension OpenAI { try await createTranscription(from: payload).async() } + func createTranscription(from payload: CreateTranscriptionPayload) async throws -> String { + try await createTranscription(from: payload).async() + } + func createTranslation(from payload: CreateTranslationPayload) async throws -> Translation { try await createTranslation(from: payload).async() } + func createTranslation(from payload: CreateTranslationPayload) async throws -> String { + try await createTranslation(from: payload).async() + } + }