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

perf: Enhance a bit the voice recognition

Clémence Lesné420f2e2ac890
diff --git a/app/helpers/call_llm.py b/app/helpers/call_llm.py
index 0feba23..e329d1e 100644
--- a/app/helpers/call_llm.py
+++ b/app/helpers/call_llm.py
@@ -13,6 +13,7 @@ from azure.cognitiveservices.speech.audio import AudioStreamFormat, PushAudioInp
from azure.communication.callautomation.aio import CallAutomationClient
from openai import APIError
from pydub import AudioSegment
+from pydub.effects import high_pass_filter, low_pass_filter
from app.helpers.call_utils import (
handle_clear_queue,
@@ -635,6 +636,10 @@ async def _in_audio( # noqa: PLR0913
# Confirm ASAP that the event is processed
in_stream.task_done()
+ # Apply high-pass and low-pass filters in a simple attempt to reduce noise
+ in_audio = high_pass_filter(in_audio, 200)
+ in_audio = low_pass_filter(in_audio, 3000)
+
# Always add the audio to the buffer
assert isinstance(in_audio.raw_data, bytes)
out_stream.write(in_audio.raw_data)