Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift - How can I convert Saved Audio file conversations to Text?

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.

like image 400
Ali Ihsan URAL Avatar asked Mar 23 '18 06:03

Ali Ihsan URAL


People also ask

How do I convert pre recorded audio to text?

Upload an audio file Make sure you're signed in to Microsoft 365, using the new Microsoft Edge or Chrome. Go to Home > Dictate dropdown > Transcribe. In the Transcribe pane, select Upload audio. Choose an audio file from the file picker.

How do I convert speech to text in iOS Swift?

Integrate Speech Recognition swift , create a new state object named speechRecognizer . The initializer requests access to the speech recognizer and microphone the first time the system calls the object. You'll begin transcribing when the meeting view appears and stop recording when the meeting view disappears.


1 Answers

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.

like image 104
Sagar Chauhan Avatar answered Nov 10 '22 16:11

Sagar Chauhan