Home > AI > IOS > Speech >

SFSpeechURLRecognitionRequest

A request to recognize speech in a recorded audio file.

Example:

func recognizeFile(url:NSURL) {
        guard let myRecognizer = SFSpeechRecognizer(locale: Locale(identifier: "hi")) else {
          // A recognizer is not supported for the current locale
          return
       }
       
        if !myRecognizer.isAvailable {
          // The recognizer is not available right now
          return
       }

       let request = SFSpeechURLRecognitionRequest(url: url)
       myRecognizer.recognitionTask(with: request) { (result, error) in
          guard let result = result else {
             // Recognition failed, so check error for details and handle it
             return
          }

          // Print the speech that has been recognized so far
          if result.isFinal {
             print("Speech in the file is \(result.bestTranscription.formattedString)")
          }
       }
    }

Leave a Reply