I am building and app that utilizes speech recognition to translate speech to text. Everything works fine but I want to save the audio recording so that I can compare what was said to what was transcribe. Here's my recording code
func StartRecording() -> String{
// Configure the audio session for the app.
let audioSession = AVAudioSession.sharedInstance()
try! audioSession.setCategory(.record, mode: .measurement, options: .duckOthers)
try! audioSession.setActive(true, options: .notifyOthersOnDeactivation)
let inputNode = audioEngine.inputNode
//
let recordingFormat = inputNode.outputFormat(forBus: 0)
inputNode.installTap(onBus: 0, bufferSize: 1024, format: recordingFormat) { (buffer: AVAudioPCMBuffer, when: AVAudioTime) in
self.recognitionRequest?.append(buffer)
}
audioEngine.prepare()
try! audioEngine.start()
// Create and configure the speech recognition request.
recognitionRequest = SFSpeechAudioBufferRecognitionRequest()
guard let recognitionRequest = recognitionRequest else { fatalError("Unable to create a SFSpeechAudioBufferRecognitionRequest object") }
recognitionRequest.shouldReportPartialResults = true
// Create a recognition task for the speech recognition session.
// Keep a reference to the task so that it can be canceled.
recognitionTask = speechRecognizer.recognitionTask(with: recognitionRequest) { result, error in
var isFinal = false
if let result = result {
// Update the text view with the results.
self.recognizedText = result.bestTranscription.formattedString
isFinal = result.isFinal
}
if error != nil || isFinal {
// Stop recognizing speech if there is a problem.
self.audioEngine.stop()
inputNode.removeTap(onBus: 0)
self.recognitionRequest = nil
self.recognitionTask = nil
}
}
return recognizedText
}
I am trying to upload the captured audio to aws s3 with this function
func tapUploadVideo(_ sender: Any) {
//guard let path = Bundle.main.path(forResource: "Video", ofType: "mov") else { return }
let videoUrl = URL(fileURLWithPath: "your video file path")
AWSS3Manager.shared.uploadVideo(videoUrl: videoUrl, progress: { [weak self] (progress) in
guard let strongSelf = self else { return }
strongSelf.progressView.progress = Float(progress)
}) { [weak self] (uploadedFileUrl, error) in
guard let strongSelf = self else { return }
if let finalPath = uploadedFileUrl as? String {
strongSelf.s3UrlLabel.text = "Uploaded file url: " + finalPath
} else {
print("\(String(describing: error?.localizedDescription))")
}
}
}
How could I get the captured audio local url?