TalkAm 如何在 Spitch、Intron 與 Gemini 間路由 Pidgin、Yoruba 和 Hausa 語音轉文字
Speech-to-Text for Nigerian Languages: Routing Pidgin, Yoruba and Hausa Across Spitch, Intron and Gemini
TalkAm 為 WhatsApp 語音銀行助理設計語音轉文字流程,按語言設定將 Pidgin、Yoruba 和 Hausa 語音路由至 Spitch、Intron 或 Gemini。
TalkAm is a voice banking assistant on WhatsApp. You send a voice note in Pidgin, Yoruba or Hausa ("check my balance", "send 5,000 to my sister") and it answers by voice in the same language. Before any language model can understand that note, it has to become text. That step, speech-to-text, is where most voice products quietly fail Nigerian users.
This article walks through how the speech service routes each voice note across three providers, Spitch, Intron and Google Gemini, and the rules that keep a bad transcript from ever touching someone's money. The service is Python (FastAPI); the banking core it reports to is Laravel.
The failure that shapes everything
Speech recognition has a nasty failure mode. Send a Hausa voice note through a model built for Yoruba and you don't get an error. You get a fluent, confident transcript of words nobody said.
For a chat app that's an annoyance. For banking it's dangerous, because that transcript flows straight into intent extraction looking like a perfectly normal input. So the whole design follows one rule: a wrong answer is worse than no answer. Every decision below is that rule applied somewhere.
1. One interface per vendor
Each provider sits behind the same small interface. A provider declares which languages it supports and whether it claims to handle code-switched speech, and it implements two methods:
class SpeechProvider(ABC):
name: str = "unnamed"
supported_languages: tuple[Language, ...] = ()
supports_code_switching: bool = False
@abstractmethod
def transcribe(self, audio_ref: str, language: Language) -> Transcription: ...
@abstractmethod
def synthesize(self, text: str, language: Language) -> Synthesis: ...
Spitch, Intron and Gemini each get one adapter. Swapping a provider is a configuration change, not a code change. Every transcript also records the slug of the provider that produced it, so an audit months later can still say which vendor heard what.
The languages are a closed enum: Pidgin, Yoruba, Hausa. Igbo is on the backlog and deliberately absent. There is no placeholder for it, so any attempt to route Igbo fails loudly instead of half-working.
2. Refuse rather than attempt
If a provider is asked for a language it doesn't claim, it raises instead of trying:
def assert_supports(self, language: Language) -> None:
if not self.supports(language):
raise UnsupportedLanguageError(
f"Provider {self.name!r} does not support {language.value!r}."
)
This looks fussy until you remember the failure mode. Forcing a Hausa utterance through a model that doesn't support Hausa returns plausible text. An exception, on the other hand, can be handled.
3. Route per language, not per vendor
The obvious design is to pick the "best" speech vendor and use it for everything. I didn't, because there's no reason to expect one vendor to win in every language. Each language gets its own route in configuration (TALKAM_ASR_PIDGIN, TALKAM_ASR_YORUBA, TALKAM_ASR_HAUSA, plus one for mixed speech), and the same for text-to-speech.
The routes are meant to be filled from evidence. The repo includes a small benchmark harness that measures word error rate per provider per language over self-recorded audio, about 50 utterances per language covering all six banking intents plus off-topic ones. Its README is blunt about recording conditions: market noise, the street, a bad phone mic. A benchmark recorded in a quiet room picks the wrong provider, because it measures a situation users are never in.
4. Identify the language first, and let the user's choice win
Language identification is its own step, before transcription, behind its own interface. It returns a language and a confidence, not a transcript. Doing it as a side effect of transcription would mean the audio had already gone through some model's assumptions before anyone decided which model was right for it.
The routing rule is deliberately lopsided. At onboarding, the user picks their language. Automatic detection can only override that choice at 0.85 confidence or above:
if identification.confidence >= self._threshold:
return RoutingDecision(language=identification.language,
reason="detection_above_threshold", ...)
return RoutingDecision(language=preferred_language,
reason="detection_below_threshold", ...)
A user who chose Hausa has told us something reliable. A detector that is 60% sure the audio is Yoruba has told us very little. Each decision also stores its reason, the detection confidence and the threshold, because when a transcript comes back as nonsense the first question is which model it went through and why. That answer has to be recorded at the time, not reconstructed afterwards.
5. Code-switching goes only to providers that claim it
Most urban Nigerian speech mixes languages mid-sentence. "Abeg send 2k to Tunde" is Pidgin, English and a Yoruba name in five words. When identification says an utterance is code-switched, there is no single-language model that fits.
In TalkAm, the Intron and Gemini adapters declare code-switch support and the Spitch adapter doesn't. The registry checks that claim at the point of use:
def for_code_switched_audio(self) -> SpeechProvider:
provider = self._resolve(self._asr_routes, MIXED, "code-switch ASR")
if not provider.supports_code_switching:
raise ProviderNotConfiguredError(
f"Provider {provider.name!r} is routed for code-switched audio "
"but does not claim code-switch support."
)
return provider
A route pointing mixed speech at a single-language provider is a misconfiguration, and it surfaces as an error instead of a stream of confidently wrong transcripts.
6. A fallback chain, with one deliberate reorder
Providers fail: timeouts, outages, a 500 at the worst moment. So the pipeline builds an ordered list: the configured primary first, then the fallbacks from TALKAM_ASR_FALLBACKS, skipping any that don't support the language (or, for mixed speech, don't claim code-switching). It tries them in order, and an empty transcript counts as a failure, not a success.
There's one reorder. When the conversation is waiting for digits, an account number or a PIN prompt, the chain moves Spitch to the front:
if awaiting_account_number or awaiting_pin:
providers = sorted(providers, key=lambda p: 0 if p.name == "spitch" else 1)
If every provider fails, the result is transcription_unavailable, and the user gets an in-language prompt to try again. Nobody's money moves on a guess.
7. What happens to the transcript next
Getting text back is not the end of the speech service's job. The order of the next steps matters as much as the routing:
- PIN guard, immediately. If the session was waiting for a PIN, or the utterance is nothing but digits and nothing asked for digits, the transcript is replaced with a fixed marker before anything else reads it. Placing this check after extraction would mean the digits had already been sent to an LLM.
- Confidence floor. Transcripts below the floor never go to extraction, because an intent extracted from a transcript the recogniser itself doubts is a confident answer built on a guess, and it costs an LLM call.
- Intent extraction. Claude maps the text to one of six closed intents with a schema. Low confidence takes the in-language fallback.
- A proposal, not a command. The speech service never moves money. It returns an intent and entities; the Laravel core re-validates every field, including the amount.
What each provider owns, and what it never decides
- Spitch, Intron, Gemini own one thing: turning audio into text (and text into speech) in a language they claim to support.
- They never decide which language the user speaks, whether a transcript is trustworthy enough to act on, or anything about money.
- The router decides the language. The pipeline decides whether text is safe to read. The core decides what happens to an account.
The trade-offs
This is more code than a single vendor SDK call. Three adapters, a registry, a router and a benchmark harness is a lot to maintain for one feature, and every new vendor has to fit the interface.
There's also an honest gap. Today the adapters report a fixed confidence per vendor rather than a score that comes back with each transcript. That makes the confidence floor more of a seam waiting for benchmark numbers than a live filter. I'd rather have the seam in place, documented as such, than bolt it on after the first bad transcript.
What I'd tell anyone building voice for Nigerian languages
- Treat a wrong-language transcript as the main risk, not an edge case.
- Route per language from measurements, and measure in noise.
- Let the user's own language choice beat a low-confidence detector.
- Send code-switched speech only to providers that claim to handle it.
- Keep the speech layer out of every decision that touches money.
If you've shipped speech features for African languages, how do you pick a provider per language, and what did your benchmark show that the vendor's docs didn't?
來源:DEV Community · dev.to