Skip to content

Commit

Permalink
quality: Add a feature for STT complete timeout
Browse files Browse the repository at this point in the history
  • Loading branch information
clemlesne committed Dec 14, 2024
1 parent a2b484c commit 24144a9
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -477,6 +477,7 @@ Conversation options are represented as features. They can be configured from Ap
| `callback_timeout_hour` | The timeout for a callback in hours. Set 0 to disable. | `int` | 3 |
| `phone_silence_timeout_sec` | Amount of silence in secs to trigger a warning message from the assistant. | `int` | 20 |
| `recognition_retry_max` | TThe maximum number of retries for voice recognition. Minimum of 1. | `int` | 3 |
| `recognition_stt_complete_timeout_ms` | The timeout for STT completion in milliseconds. | `int` | 100 |
| `recording_enabled` | Whether call recording is enabled. | `bool` | false |
| `slow_llm_for_chat` | Whether to use the slow LLM for chat. | `bool` | false |
| `vad_cutoff_timeout_ms` | The cutoff timeout for voice activity detection in milliseconds. | `int` | 250 |
Expand Down
6 changes: 5 additions & 1 deletion app/helpers/call_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
answer_hard_timeout_sec,
answer_soft_timeout_sec,
phone_silence_timeout_sec,
recognition_stt_complete_timeout_ms,
vad_cutoff_timeout_ms,
vad_silence_timeout_ms,
)
Expand Down Expand Up @@ -260,7 +261,10 @@ async def _response_callback(_retry: bool = False) -> None:

# Wait the complete recognition for 50ms maximum
try:
await asyncio.wait_for(stt_complete_gate.wait(), timeout=0.05)
await asyncio.wait_for(
stt_complete_gate.wait(),
timeout=await recognition_stt_complete_timeout_ms(scheduler) / 1000,
)
except TimeoutError:
logger.debug("Complete recognition timeout, using partial recognition")

Expand Down
12 changes: 12 additions & 0 deletions app/helpers/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,18 @@ async def recognition_retry_max(scheduler: Scheduler) -> int:
)


async def recognition_stt_complete_timeout_ms(scheduler: Scheduler) -> int:
"""
The timeout for STT completion in milliseconds.
"""
return await _default(
default=100,
key="recognition_stt_complete_timeout_ms",
scheduler=scheduler,
type_res=int,
)


async def _default( # noqa: PLR0913
default: T,
key: str,
Expand Down
1 change: 1 addition & 0 deletions cicd/bicep/app.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -905,6 +905,7 @@ resource configValues 'Microsoft.AppConfiguration/configurationStores/keyValues@
callback_timeout_hour: 3
phone_silence_timeout_sec: 20
recognition_retry_max: 2
recognition_stt_complete_timeout_ms: 100
recording_enabled: false
slow_llm_for_chat: false
vad_cutoff_timeout_ms: 250
Expand Down

0 comments on commit 24144a9

Please sign in to comment.