Class

SFSpeechURLRecognitionRequest

A request to recognize speech in a recorded audio file.

Declaration

class SFSpeechURLRecognitionRequest : SFSpeechRecognitionRequest

Overview

Use an SFSpeechURLRecognitionRequest object to perform speech recognition on the contents of an existing audio file.

Listing 1 shows a method that performs speech recognition on the contents of a specified audio file. The method uses the default locale and prints the resulting text to standard output.

Listing 1

Getting a speech recognizer and making a recognition request

func recognizeFile(url:NSURL) {
   guard let myRecognizer = SFSpeechRecognizer() 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)")
      }
   }
}

Topics

Creating a Speech Recognition Request

init(url: URL)

Creates a speech recognition request, initialized with the specified URL.

Accessing the URL of the Audio File

var url: URL

The URL of the audio file.

Relationships

Conforms To

See Also

Audio Sources

Recognizing Speech in Live Audio

Perform speech recognition on audio coming from the microphone of an iOS device.

class SFSpeechAudioBufferRecognitionRequest

A request to recognize speech from captured audio content, such as audio from the device's microphone.

class SFSpeechRecognitionRequest

An abstract class representing a request to recognize speech from an audio source.