Is it possible to clarify user's utterance when th...
# ask-ai
b
Is it possible to clarify user's utterance when the STT does not have high confidence on what the user just said?
t
Thanks for reaching out, Masayuki. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
You're asking whether you can clarify a user's utterance when the STT result has low confidence — yes, you can. Here are practical ways to handle it: • Increase endpointing delay so the system waits longer before closing the user's turn (use
max_endpointing_delay
, default 6.0s) to give the user more time to finish speaking. • Detect low-confidence transcriptions and prompt the user for confirmation, e.g., "I didn't catch that — could you repeat or clarify?" — implement this in your agent's dialog logic. • Tune STT plugin thresholds (for example AssemblyAI's
end_of_turn_confidence_threshold
, default 0.7) so endpointing and turn detection better match your use case. If you want, tell me which STT plugin you're using and whether you prefer automatic confirmation prompts or silent longer endpointing, and I’ll suggest specific setting values and a short confirmation prompt flow. Sources: How does end-of-utterance detection work in conversations? | examples/frontdesk | livekit/livekit_composite | DeepWiki | AssemblyAI plugin guide | LiveKit Docs
b
How can we detect low-confidence and prompt the user for confirmation?
t
You're asking how to detect low-confidence STT results and prompt the user for confirmation. Below is a concise, actionable approach you can implement in LiveKit Agents. 1) Detect low-confidence • Check the STT plugin's confidence score on each transcription result (e.g.,
confidence
,
end_of_turn_confidence
, or similar field returned by the plugin). • Define a threshold (common defaults: ~0.7). If score < threshold, mark the utterance as low-confidence. • Optionally combine signals: low confidence + short utterance length, lots of filler words, or abrupt endpointing increases likelihood of error. 2) Adjust endpointing to reduce false positives • Increase
max_endpointing_delay
(default 6.0s) to allow users to continue speaking before the agent finalizes the turn. This reduces premature low-confidence results. 3) Confirmation prompt strategies • Explicit confirmation (recommended for critical actions): ◦ Agent asks: "I didn't catch that. Did you say: '<transcript>'?" ◦ If user confirms, proceed. If user denies, ask to repeat or offer multiple-choice clarifying options. • Implicit confirmation (less intrusive): ◦ Agent repeats interpreted action: "Okay, I'll set a reminder for 3 PM." Wait for user correction within a short window. • Clarification question for partial content: ◦ If only part is unclear, ask a focused question: "Do you mean tomorrow or Thursday?" 4) Minimal implementation flow (pseudocode) • On transcription result: a. If `confidence >= threshold`: proceed with normal handling. b. Else: • If automatic retries enabled: extend endpointing or request short reprompt (e.g., "Could you repeat that once?"). • Else send confirmation prompt: "I didn't catch that—did you mean '<transcript>'? (yes/no)" • On "yes": accept. On "no": ask user to repeat or offer alternatives. 5) UX tips • Use concise prompts and limit confirmations to important turns to avoid user frustration. • For voice UX, allow simple affirmative/negative replies and small corrections (e.g., "No, 4 PM"). • Consider offering a confidence-aware fallback (e.g., display N-best alternatives in a UI when available). If you tell me which STT plugin you use (AssemblyAI, Whisper, etc.) and whether you prefer explicit or implicit confirmations, I can suggest exact fields to check and a short prompt script tuned to that plugin.
b
Could you show me an example code for that?
t
You're asking for example code to detect low-confidence STT results and prompt the user for confirmation. Below is a concise Node.js example showing how to: • check STT confidence, • extend endpointing briefly for retries, • prompt the user with an explicit confirmation flow, • handle yes/no responses. This example assumes: • you receive transcription events with a
transcript
and
confidence
field from your STT plugin, • you can send TTS or text responses back to the user, • you can control endpointing via
max_endpointing_delay
or re-open the turn (illustrated as a retry flag). Example (Node.js / pseudocode style):
Copy code
// Configuration
const CONFIDENCE_THRESHOLD = 0.7;
const MAX_RETRIES = 1; // allow one automatic retry before prompting
const RETRY_ENDPOINTING_DELAY = 2.0; // seconds to wait for user to continue after low-confidence

// State per active user/session
const sessionState = {
  retriesLeft: MAX_RETRIES,
  awaitingConfirmation: false,
  lastTranscript: null,
};

// Called when the STT plugin returns a final transcription for a turn
async function onTranscription(session, result) {
  // result: { transcript: string, confidence: number, end_of_turn: boolean }
  const transcript = result.transcript.trim();
  const confidence = result.confidence ?? 0;

  sessionState.lastTranscript = transcript;

  if (confidence >= CONFIDENCE_THRESHOLD) {
    // High-confidence: proceed normally
    await handleIntent(session, transcript);
    resetSession(session);
    return;
  }

  // Low-confidence branch
  if (sessionState.retriesLeft > 0) {
    // Ask to continue speaking by extending endpointing / giving a short retry window
    sessionState.retriesLeft -= 1;
    await sendTTS(session, "I missed that — you can continue speaking for a moment.");
    // Here you would programmatically extend endpointing or set a short delay to accept more audio
    await waitSeconds(RETRY_ENDPOINTING_DELAY);
    // After delay, rely on subsequent transcription callback to re-enter onTranscription
    return;
  }

  // No retries left: prompt for explicit confirmation
  sessionState.awaitingConfirmation = true;
  await sendTTS(session, `I didn't catch that clearly. Did you say: "${transcript}"? Please say Yes or No.`);
  // Now wait for next user utterance which should be yes/no (handled in onUserReply)
}

// Called when user replies while awaiting confirmation
async function onUserReply(session, replyResult) {
  // replyResult: { transcript: string, confidence: number }
  const reply = replyResult.transcript.toLowerCase();

  if (sessionState.awaitingConfirmation) {
    if (reply.includes("yes") || reply.includes("correct") || reply.includes("yep")) {
      // confirmed: proceed with last transcript
      sessionState.awaitingConfirmation = false;
      await sendTTS(session, "Great — I'll proceed.");
      await handleIntent(session, sessionState.lastTranscript);
      resetSession(session);
      return;
    }

    if (reply.includes("no") || reply.includes("wrong") || reply.includes("nope")) {
      // user denied: ask to repeat or offer clarifying choices
      sessionState.awaitingConfirmation = false;
      await sendTTS(session, "Sorry about that. Could you repeat that, or say the option you'd like?");
      // Reset retries so we can allow another short retry
      sessionState.retriesLeft = MAX_RETRIES;
      return;
    }

    // If unclear yes/no, reprompt once
    await sendTTS(session, "Please say Yes if that's correct, or No if it's not.");
    return;
  }

  // Not awaiting confirmation: handle normally (could be a new command)
  await onTranscription(session, replyResult);
}

// Helpers (stubbed)
function resetSession(session) {
  sessionState.retriesLeft = MAX_RETRIES;
  sessionState.awaitingConfirmation = false;
  sessionState.lastTranscript = null;
}

async function handleIntent(session, transcript) {
  // Replace with your intent handling / NLU flow
  console.log("Handling intent for:", transcript);
  await sendTTS(session, `Understood: ${transcript}`);
}

async function sendTTS(session, text) {
  // Send TTS or text response to the user via LiveKit agent output
  console.log("TTS ->", text);
}

function waitSeconds(sec) {
  return new Promise(r => setTimeout(r, sec * 1000));
}
Notes and quick tips: • Check the exact field names your STT plugin returns (
confidence
,
end_of_turn_confidence
, etc.) and use those in the code. • For AssemblyAI-like plugins, you can also inspect
end_of_turn_confidence
and tune
end_of_turn_confidence_threshold
. • Keep confirmation prompts short and only use explicit confirmation for critical actions to avoid annoying users. • Consider offering an N-best list (if your STT provides alternatives) in the confirmation ("Did you mean A, B, or C?"). Would you like this adapted to a specific STT plugin (AssemblyAI, Whisper, etc.) or to a different language/framework?