Skip to content

Instantly share code, notes, and snippets.

@jasdev
Last active Jan 24, 2021
Embed
What would you like to do?
A sketch of a transcription effect in TCA.
import ComposableArchitecture
let transcriptionEffect: (URL) -> Effect<String, NSError> = { audioURL in
.future { callback in
guard
let speechRecognizer = SFSpeechRecognizer(),
speechRecognizer.isAvailable // (1)
else {
callback(
.failure(
NSError(
domain: "com.jasdev.CaptionsGeneration",
code: 1,
userInfo: nil
)
)
)
return
}
let request = SFSpeechURLRecognitionRequest(url: audioURL)
request.shouldReportPartialResults = false // (2)
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
)
)
)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment