I work on speech recognition. I solve the text-to-speech and speech-to-text with IOS frameworks. But now i want to convert saved audio file conversations to text. How can i solve this ? Thank you for all replies.
Asked
Active
Viewed 7,195 times
8
-
please look into it : https://stackoverflow.com/a/47330346/3278326 – Jarvis The Avenger Mar 23 '18 at 06:48
1 Answers
20
I have worked on same things which are working for me.
I have audio file in my project bundle which. So I have written following code to convert audio to text.
let audioURL = Bundle.main.url(forResource: "Song", withExtension: "mov")
let recognizer = SFSpeechRecognizer(locale: Locale(identifier: "en-US"))
let request = SFSpeechURLRecognitionRequest(url: audioURL!)
request.shouldReportPartialResults = true
if (recognizer?.isAvailable)! {
recognizer?.recognitionTask(with: request) { result, error in
guard error == nil else { print("Error: \(error!)"); return }
guard let result = result else { print("No result!"); return }
print(result.bestTranscription.formattedString)
}
} else {
print("Device doesn't support speech recognition")
}
First get audio url from where you have store audio file.
Then create instance of SFSpeechRecognizer
with locale that you have want.
Create instance of SFSpeechURLRecognitionRequest
which are used to requesting recognitionTask
.
recognitionTask
will give you result and error. Where result contains bestTranscription.formattedString
. formmatedString
is your test result of audio file.
If set request.shouldReportPartialResults = true
, this will give your partial result of every line speak in audio.
I hope this will help you.

Sagar Chauhan
- 5,715
- 2
- 22
- 56
-
Thanks Dude it works. The difference between speech-to-text just change "SFSpeechAudioBufferRecognitionRequest" to "SFSpeechURLRecognitionRequest" i think. – Ali Ihsan URAL Mar 23 '18 at 07:24
-
In above code we give url of song or mp3 file added to bundle – Gangireddy Rami Reddy Aug 02 '18 at 06:27
-
-
I tried this but for some reason I get `[Utility] +[AFAggregator logDictationFailedWithError:] Error Domain=kAFAssistantErrorDomain Code=209 "(null)" Error: Error Domain=kAFAssistantErrorDomain Code=209 "(null)"` – Mansidak Feb 02 '23 at 14:23