Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A non-TCA version of the transcription effect.
let transcriptionEffect: (URL) -> AnyPublisher<String, NSError> = { audioURL in
Deferred {
Future { callback in
guard
let speechRecognizer = SFSpeechRecognizer(),
speechRecognizer.isAvailable
else {
callback(
.failure(
NSError(
domain: "com.jasdev.CaptionsGeneration",
code: 1,
userInfo: nil
)
)
)
return
}
let request = SFSpeechURLRecognitionRequest(url: audioURL)
request.shouldReportPartialResults = false
speechRecognizer.recognitionTask(with: request) { [weak request] result, error in
if let error = error {
callback(.failure(error as NSError))
} else {
callback(
.success(
transcriptionSegmentsToSubRipText(
result!
.bestTranscription
.segments
)
)
)
}
}
}
}
.eraseToAnyPublisher()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment