---
title: "recognitionTask(with:resultHandler:)"
framework: speech
role: symbol
role_heading: Instance Method
path: "speech/sfspeechrecognizer/recognitiontask(with:resulthandler:)"
---

# recognitionTask(with:resultHandler:)

Executes the speech recognition request and delivers the results to the specified handler block.

## Declaration

```swift
func recognitionTask(with request: SFSpeechRecognitionRequest, resultHandler: @escaping (SFSpeechRecognitionResult?, (any Error)?) -> Void) -> SFSpeechRecognitionTask
```

## Parameters

- `request`: A request (in an doc://com.apple.speech/documentation/Speech/SFSpeechRecognitionRequest object) to recognize speech from an audio source.
- `resultHandler`: The block to call when partial or final results are available, or when an error occurs. If the doc://com.apple.speech/documentation/Speech/SFSpeechRecognitionRequest/shouldReportPartialResults property is true, this block may be called multiple times to deliver the partial and final results. The block has no return value and takes the following parameters:

## Return Value

Return Value The task object you can use to manage an in-progress recognition request.

## Discussion

Discussion Use this method to initiate the speech recognition process on the audio contained in the request object. This method executes asynchronously and returns a SFSpeechRecognitionTask object that you can use to cancel or finalize the recognition process later. As results become available, the method calls the block in the resultHandler parameter.

## See Also

### Performing speech recognition on audio

- [recognitionTask(with:delegate:)](speech/sfspeechrecognizer/recognitiontask(with:delegate:).md)
- [SFSpeechRecognitionTaskDelegate](speech/sfspeechrecognitiontaskdelegate.md)
