STSRData
Carries Conversation-level speech-recognition data to STConversationCallback.conversationReceivedSpeechRecognition(moduleID:data:).
Overview
The conversation callback receives this object when speech recognition produces information relevant to the active conversation. Inspect the recognized utterance, recognition details, and hypothesis type before deciding how to proceed. The client can mark a hypothesis as rejected during the callback; changes that must affect the current turn should be made synchronously.
public final class STSRData {
public internal(set) var recognitionData: STSpeechRecognitionEventData?
public internal(set) var hypothesisType: STMediaEventType?
public internal(set) var taskID: String?
public internal(set) var utterance: String?
public var clientRejectedHypothesis: Bool = false
public var numberOfSegments: Int { get }
public var confidence: Float { get }
}
STSRData is created and populated by SpeechTiles; its initializer is internal. Recognition information is readable by the application, while clientRejectedHypothesis is intentionally writable so the application can participate in validation of a recognition result.
Properties
recognitionData
The typed recognition-event data produced by the media recognition layer. It can include the recognized hypothesis, status, engine information, error information, and recognition segments.
The setter is internal, so applications read this value but do not replace it.
hypothesisType
The STMediaEventType associated with the delivered recognition data. Applications can use this to distinguish, for example, a final .srHypothesis from other recognition event types.
The setter is internal.
taskID
The recognition task identifier associated with this data, when one is available.
The setter is internal.
utterance
Conversation-level utterance text associated with the recognition data, when available.
The setter is internal.
clientRejectedHypothesis
public var clientRejectedHypothesis: Bool = false
Allows the application to tell SpeechTiles that a recognition hypothesis should be rejected by application semantics even though the recognizer produced it.
When rejection must affect the current Conversation decision, set this property synchronously before the callback returns.
numberOfSegments
Returns the number of recognition segments in recognitionData. Returns 0 when recognition data or segments are unavailable.
confidence
Returns the arithmetic mean of the confidence values for all recognition segments. Returns 0.0 when there are no segments.
This is a segment-average convenience value supplied by STSRData; it is not a separate confidence value reported by the recognizer.
Example
func conversationReceivedSpeechRecognition(
moduleID: String,
data: STSRData
) {
guard data.hypothesisType == .srHypothesis,
let hypothesis = data.recognitionData?.hypothesis else {
return
}
guard applicationAccepts(hypothesis) else {
data.clientRejectedHypothesis = true
return
}
_ = conversation.setRuntimeField(
"CollectedValue",
value: hypothesis
)
}
Synchronous decision semantics
If the application changes clientRejectedHypothesis, runtime fields, or user intent in this callback and the current Conversation operation must observe that change, complete the change before the callback returns. UI publication can be dispatched separately.
Purpose and usage
Inspect recognition results passed to `STConversationCallback.conversationRecognitionResult`. The recognition data is provided by the conversation runtime.
Properties
recognitionData— Declared asSTSpeechRecognitionEventData.hypothesisType— Declared asSTMediaEventType.taskID— Declared as String.utterance— Declared as String.clientRejectedHypothesis— Declared as Bool.numberOfSegments— Declared as Int.confidence— Declared as Float.
Swift example
// In your STConversationCallback implementation, inspect the STSRData argument.
Where this type is used
- setconversationcallback — STConversationRunner