STSpeechRecognitionEventData
Carries typed data for speech-recognition media events.
Overview
Speech recognition results and engine status, including partial or final hypotheses, errors, and per-segment detail when available. Inspect the event type to distinguish partial hypotheses, final hypotheses, and completion. This is the associated payload of STMediaEventData.speechRecognition; inspect the enclosing STMediaEvent to identify the component and event type.
The payload identifies the recognition engine and result status, and may include a hypothesis, an error message, and STSpeechRecognitionSegment entries.
Speech-recognition event types include partial hypotheses, hypotheses, and recognition completion.
public struct STSpeechRecognitionEventData: Sendable {
public let engine: String
public let status: STSRResultStatus
public let hypothesis: String?
public let error: String?
public let segments: [STSpeechRecognitionSegment]
public init(
engine: String,
status: STSRResultStatus,
hypothesis: String? = nil,
error: String? = nil,
segments: [STSpeechRecognitionSegment] = []
)
}
Properties
engine— Identifier of the speech-recognition engine producing the event.status— Recognition result status; see STSRResultStatus for the available states.hypothesis— Optional recognized text associated with this event.error— Optional error information reported by the recognition engine.segments— Segment-level recognition data; may be empty when the engine supplies no segments.
Purpose and usage
Carries typed data for speech-recognition media events. Inspect this value when processing the relevant asynchronous event.
Event payload mapping
STMediaEventData.speechRecognition carries this structure. Match the associated enum case when handling STMediaEvent.data. The event type and function identify the occurrence; the payload provides its event-specific details.
switch event.data {
case .speechRecognition(let recognition):
if let hypothesis = recognition.hypothesis {
print(hypothesis)
}
for segment in recognition.segments {
print(segment.resolvedSubstring)
}
default:
break
}