iOS 视频文件中的语音到文本不同步

问题描述 投票:0回答:0

尝试创建一个视频字幕应用程序。我正在使用 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)
        }
    })
}
ios swift speech-to-text sfspeechrecognizer
© www.soinside.com 2019 - 2024. All rights reserved.