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.
| Code | Language / region |
|---|---|
en-KE | English (Kenya) |
en-NG | English (Nigeria) |
sw-KE | Swahili (Kenya) |
am-ET | Amharic (Ethiopia) |
fr-CI | French (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.
π Related Resourcesβ
Last Updated: May 2026