SpeechTilesAndamento Docs
Get started
SDK Reference · Callback

conversationReceivedSpeechRecognition

Delivers Conversation-level speech-recognition data.

func conversationReceivedSpeechRecognition(
    moduleID: String,
    data: STSRData
)

Applications can inspect the recognition result and synchronously affect the current Conversation decision by updating runtime fields, setting user intent, or setting data.clientRejectedHypothesis.

Behavior

Delivers STSRData for recognition associated with a conversation module. The application can accept or reject hypotheses or provide a user intent.

Parameters

  • moduleID (String): Identifier of the conversation module associated with this callback.
  • data (STSRData): Recognition data, including the current hypothesis and client-rejection flag.

Timing and execution

When a runtime-field update or client decision must affect the framework immediately, perform it synchronously within this callback, before returning. UI updates that do not affect the immediate conversation decision can be dispatched separately.

Swift example: recognize intent and reject unmatched hypotheses

Implement this method in a class conforming to STConversationCallback. The runner property refers to an initialized STConversationRunner. The application-defined mapHypothesisToIntent(_:) helper maps recognized words to the intents defined in the conversation configuration.

The example leaves empty hypotheses to normal timeout handling. The intent must be set synchronously to stop recognition immediately and allow the conversation to act on it.

public func conversationReceivedSpeechRecognition(
    moduleID: String,
    data: STSRData
) {
    guard moduleID == "node.ask" else { return }

    let hypothesis = (data.recognitionData?.hypothesis ?? "")
        .trimmingCharacters(in: .whitespacesAndNewlines)
    guard !hypothesis.isEmpty else { return }

    if let intent = mapHypothesisToIntent(hypothesis) {
        _ = runner.setUserIntent(intent) // Synchronous decision.
    } else {
        data.clientRejectedHypothesis = true
    }
}

// Application-defined helper; adapt to your conversation's intents.
private func mapHypothesisToIntent(_ text: String) -> String? {
    let normalized = text.lowercased()
    if normalized.contains("help") { return "UserRequest" }
    return nil
}

See Also