adorable-bear-14321
04/15/2026, 9:44 AMtall-airline-16756
04/15/2026, 9:44 AMtall-airline-16756
04/15/2026, 9:44 AMadorable-bear-14321
04/15/2026, 9:48 AMdef create_stt(self, agent_info: AgentInfo):
return stt.FallbackAdapter([
_build_sarvam_stt_instance(self, agent_info),
_build_azure_stt_instance(self, agent_info),
])
def _build_sarvam_stt_instance(provider: STTProvider, agent_info: AgentInfo):
stt_details: STTDetails = agent_info.config.stt_details
return sarvam.STT(
model=agent_info.model_values.stt.model or provider.get_config_value('sarvam', 'model', ),
language=stt_details.language or provider.get_config_value('sarvam', 'language', ),
mode=stt_details.mode,
prompt=stt_details.prompt or provider.get_config_value('sarvam', 'prompt', ),
high_vad_sensitivity=stt_details.high_vad_sensitivity or provider.get_config_value(
'sarvam', 'high_vad_sensitivity', ),
sample_rate=stt_details.sample_rate or provider.get_config_value('sarvam', 'sample_rate', 'int'),
flush_signal=stt_details.flush_signal or provider.get_config_value('sarvam', 'flush_signal', ),
input_audio_codec=stt_details.input_audio_codec or provider.get_config_value('sarvam', 'input_audio_codec', ),
)
def _build_azure_stt_instance(provider: STTProvider, agent_info: AgentInfo) -> azure_stt_1_3x.STT:
stt_details: STTDetails = agent_info.config.stt_details
profanity_option = AzureSTTProvider.get_profanity_option(
stt_details.profanity or provider.get_config_value('azure', 'profanity', ))
languages = stt_details.languages
if languages is None:
languages = []
single_language = stt_details.language
combined_languages = [
lang.strip()
for lang in (languages + ([single_language] if single_language else []))
if lang and lang.strip()
]
return azure_stt_1_3x.STT(
speech_key=stt_details.speech_key or provider.get_config_value('azure', 'speech_key_env', 'env'),
speech_region=stt_details.speech_region or provider.get_config_value('azure', 'speech_region_env', 'env'),
speech_auth_token=stt_details.speech_auth_token or provider.get_config_value('azure', 'speech_auth_token', ),
sample_rate=stt_details.sample_rate or provider.get_config_value('azure', 'sample_rate', 'int'),
num_channels=stt_details.num_channels or provider.get_config_value('azure', 'num_channels', 'int'),
segmentation_silence_timeout_ms=stt_details.segmentation_silence_timeout_ms or provider.get_config_value(
'azure', 'segmentation_silence_timeout_ms', 'int'),
segmentation_max_time_ms=stt_details.segmentation_max_time_ms or provider.get_config_value(
'azure', 'segmentation_max_time_ms', 'int'),
segmentation_strategy=stt_details.segmentation_strategy or provider.get_config_value(
'azure', 'segmentation_strategy', ),
language=combined_languages,
profanity=profanity_option,
)
this is the code
suppose i have passed sarvam config with language = hiiii
"unhandled exception while running the job task\nTraceback (most recent call last):\n File \"/Users/harshita.patil/whizdm-dev/livekit-agent/.venv/lib/python3.11/site-packages/opentelemetry/util/_decorator.py\", line 71, in async_wrapper\n return await func(*args, **kwargs) # type: ignore\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/Users/harshita.patil/whizdm-dev/livekit-agent/.venv/lib/python3.11/site-packages/livekit/agents/ipc/job_proc_lazy_main.py\", line 306, in _traceable_entrypoint\n await self._job_entrypoint_fnc(job_ctx)\n File \"/Users/harshita.patil/whizdm-dev/livekit-agent/agents/agent.py\", line 1052, in entrypoint\n @session.on(\"metrics_collected\")\n ^^^^^^^^^^\nAttributeError: 'NoneType' object has no attribute 'on'", "level": "ERROR", "name": "livekit.agents", "exc_info": "Traceback (most recent call last):\n File \"/Users/harshita.patil/whizdm-dev/livekit-agent/.venv/lib/python3.11/site-packages/opentelemetry/util/_decorator.py\", line 71, in async_wrapper\n return await func(*args, **kwargs) # type: ignore\n ^^^^^^^^^^^^^^^^^^^^^^^^^^^\n File \"/Users/harshita.patil/whizdm-dev/livekit-agent/.venv/lib/python3.11/site-packages/livekit/agents/ipc/job_proc_lazy_main.py\", line 306, in _traceable_entrypoint\n await self._job_entrypoint_fnc(job_ctx)\n File \"/Users/harshita.patil/whizdm-dev/livekit-agent/agents/agent.py\", line 1052, in entrypoint\n @session.on(\"metrics_collected\")\n ^^^^^^^^^^\nAttributeError: 'NoneType' object has no attribute 'on'", "pid": 59798, "job_id": "AJ_W2xx6dXw2263", "room_id": "RM_y3sADj829qxm", "timestamp": "2026-04-15T094159.954416+00:00"}
{"message":
it directly fails the stt and terminate the session instead it should switch to the fallbacktall-airline-16756
04/15/2026, 9:49 AMlanguage and other params, and default or reject invalid values so Sarvam isn’t constructed with bad input.
• Catch initialization/configuration errors and explicitly instantiate/use the fallback STT when Sarvam construction fails. Example pattern:
a. Try to build Sarvam; if it raises, log and build Azure instead.
b. Wrap session init so a failed STT build doesn’t leave session as None.
• Delay provider selection to runtime: build lightweight provider factories that validate per-request and only start the provider when audio arrives; if build fails, switch to the next provider.
• Add defensive error handling around your agent/session setup so a provider build error doesn’t terminate the whole job (ensure session is created before registering handlers, or register handlers only after successful provider setup).
If you want, I can:
• Suggest a small code patch showing how to catch Sarvam build errors and fallback to Azure.
• Review a minimal repro of the Sarvam build failure (stack trace + the exact invalid param) and draft the try/catch changes for your code.
Which would help you most?
Sources: Build Your First AI Voice Agent in Python: Complete Tutorial | LiveKit | Speech-to-text (STT) models overview | LiveKit Documentation, with interactive elements