Skip to main content

Speech Recognition in Voice Flows

Speech input lets callers say what they want instead of pressing keys. It's powerful for open-ended capture but needs careful handling of languages, noise, and low-confidence results.

πŸš€ Quick Start​

curl -X POST https://api.afriroute.ai/api/v1/voice/calls \
-H "Authorization: Bearer $AFRIROUTE_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "+254712345678",
"from": "+254700000000",
"flow": {
"say": "What city are you calling about?",
"gather": { "input": "speech", "language": "en-KE", "action_url": "https://example.com/asr" }
}
}'

πŸ—£οΈ Languages​

Set the language per gather to the caller's locale for best accuracy.

CodeLanguage / region
en-KEEnglish (Kenya)
en-NGEnglish (Nigeria)
sw-KESwahili (Kenya)
am-ETAmharic (Ethiopia)
fr-CIFrench (CΓ΄te d'Ivoire)

Offer a quick language-select menu first when your audience is multilingual.

πŸ“Š Confidence Handling​

Each result carries a confidence score (0–1). Branch on it instead of trusting every transcript.

def on_speech(req):
text, conf = req['speech_result'], req['confidence']
if conf >= 0.8:
return route(text) # act on it
if conf >= 0.5:
return confirm(text) # "Did you say Nairobi?"
return reprompt() # ask again or offer DTMF
function handleSpeech({ speech_result, confidence }) {
if (confidence >= 0.8) return act(speech_result);
if (confidence >= 0.5) return askConfirm(speech_result);
return fallbackToDTMF();
}

πŸ” Hybrid Input & Fallback​

Allow both speech and keypad in the same gather so callers in noisy areas have an out.

{
"say": "Say your account type, or press 1 for savings, 2 for current.",
"gather": { "input": "speech dtmf", "language": "en-KE", "hints": ["savings", "current"] }
}

Use hints (expected phrases) to boost recognition of domain terms like product or city names.

πŸ’‘ Best Practices​

  • Set the right language per gather β€” defaults hurt accuracy.
  • Confirm medium-confidence results before acting.
  • Provide DTMF fallback for noisy environments and accents.
  • Use hints for known vocabularies (cities, plans, names).
  • Keep prompts short so callers respond promptly.
  • Cap retries, then route to a human.

⚠️ Common Pitfalls​

  • Acting on low-confidence transcripts leads to wrong routing.
  • Long prompts cause callers to speak over the system.
  • Ignoring background noise β€” always offer a keypad path.

Last Updated: May 2026