Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use iOS 10 Speech Recognition?

How to transcribe audio into text in iOS10 using Speech.framework?

like image 407
SaRaVaNaN DM Avatar asked Feb 06 '23 17:02

SaRaVaNaN DM


1 Answers

Its very simple, just few lines of code.

let recognizer = SFSpeechRecognizer()  
let request = SFSpeechURLRecognitionRequest(url: audioFileURL)
recognizer?.recognitionTask(with: request, resultHandler: { (result, error)   in  
     if let error = error {
        print("There was an error: \(error)")
     } else {
        print (result?.bestTranscription.formattedString)
     }
})  

NOTE:
As with accessing other types of protected data, such as Calendar and Photos data, performing speech recognition requires the user’s permission (for more information about accessing protected data classes, see Security and Privacy Enhancements).

In the case of speech recognition, permission is required because data is transmitted and temporarily stored on Apple’s servers to increase the accuracy of speech recognition. To request the user’s permission, you must add the NSSpeechRecognitionUsageDescription key to your app’s Info.plist file.

Refer: http://saravnandm.blogspot.in/2016/06/ios10-speech-recognition-in-ios-10_23.html

like image 163
SaRaVaNaN DM Avatar answered Feb 13 '23 07:02

SaRaVaNaN DM