尝试创建一个视频字幕应用程序。我正在使用 UIImagePickerController 打开视频文件。可以将语音转换为文本,但文本甚至在视频上说之前就已创建。我需要它与视频同步。
如何将文本同步到视频并在说出内容时将其打印到控制台?
func processVideo(_ videoURL: URL) { 让识别器= SFSpeechRecognizer(区域设置:区域设置(标识符:“en-US”))!
let request = SFSpeechURLRecognitionRequest(url: videoURL)
recognizer?.recognitionTask(with: request, resultHandler: { [weak self] (result, error) in
if let result = result {
// Update the text overlay label with the transcribed text
let transcribedText = result.bestTranscription.formattedString
DispatchQueue.main.async {
print(transcribedText)
}
} else {
print(error)
}
})
}