35 lines
847 B
Swift
35 lines
847 B
Swift
import Foundation
|
|
|
|
actor SynthesisWorker {
|
|
enum WorkerError: Error, LocalizedError {
|
|
case pipelineUnavailable
|
|
|
|
var errorDescription: String? {
|
|
switch self {
|
|
case .pipelineUnavailable:
|
|
return "Kokoro pipeline failed to initialize."
|
|
}
|
|
}
|
|
}
|
|
|
|
private let pipeline: KokoroPipeline?
|
|
|
|
init() {
|
|
pipeline = try? KokoroPipeline()
|
|
}
|
|
|
|
func synthesize(text: String) throws -> [Float] {
|
|
guard let pipeline else {
|
|
throw WorkerError.pipelineUnavailable
|
|
}
|
|
return try pipeline.synthesize(text: text)
|
|
}
|
|
|
|
func synthesizeLong(text: String) throws -> [Float] {
|
|
guard let pipeline else {
|
|
throw WorkerError.pipelineUnavailable
|
|
}
|
|
return try pipeline.synthesizeLong(text: text)
|
|
}
|
|
}
|