Skip to content

Send a phone call from AI agent, in an API call. Or, directly call the bot from the configured phone number!

Python

feat: Allow to customize voice detection delay

Clémence Lesnéf47ecb104ff8
diff --git a/README.md b/README.md
index 0ee92ef..a7e85dd 100644
--- a/README.md
+++ b/README.md
@@ -637,6 +637,7 @@ Conversation options are represented as features. They can be configured from Ap
| `recognition_retry_max` | The maximum number of retries for voice recognition. | `int` | 2 |
| `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 seconds. | `int` | 500 |
| `vad_silence_timeout_ms` | The timeout for phone silence in seconds. | `int` | 500 |
| `vad_threshold` | The threshold for voice activity detection. | `float` | 0.5 |
diff --git a/app/helpers/call_llm.py b/app/helpers/call_llm.py
index 2923497..a7e4c55 100644
--- a/app/helpers/call_llm.py
+++ b/app/helpers/call_llm.py
@@ -24,6 +24,7 @@ from app.helpers.config import CONFIG
from app.helpers.features import (
answer_hard_timeout_sec,
answer_soft_timeout_sec,
+ vad_cutoff_timeout_ms,
vad_silence_timeout_ms,
vad_threshold,
)
@@ -611,8 +612,8 @@ async def _in_audio( # noqa: PLR0913
Start is the index of the buffer where the TTS was triggered.
"""
- # Wait 200ms before clearing the TTS queue
- await asyncio.sleep(0.2)
+ # Wait before clearing the TTS queue
+ await asyncio.sleep(await vad_cutoff_timeout_ms() / 1000)
logger.debug("Voice detected, cancelling TTS")
diff --git a/app/helpers/features.py b/app/helpers/features.py
index 6945e59..2d7757c 100644
--- a/app/helpers/features.py
+++ b/app/helpers/features.py
@@ -32,6 +32,10 @@ async def vad_silence_timeout_ms() -> int:
return await _get(key="vad_silence_timeout_ms", type_res=int) or 500
+async def vad_cutoff_timeout_ms() -> int:
+ return await _get(key="vad_cutoff_timeout_ms", type_res=int) or 500
+
+
async def vad_threshold() -> float:
return await _get(key="vad_threshold", type_res=float) or 0.5
diff --git a/cicd/bicep/app.bicep b/cicd/bicep/app.bicep
index 1c65ade..f1e68e6 100644
--- a/cicd/bicep/app.bicep
+++ b/cicd/bicep/app.bicep
@@ -905,6 +905,7 @@ resource configValues 'Microsoft.AppConfiguration/configurationStores/keyValues@
recognition_retry_max: 2
recording_enabled: false
slow_llm_for_chat: false
+ vad_cutoff_timeout_ms: 500
vad_silence_timeout_ms: 500
vad_threshold: '0.5'
}): {