how can I include the BVCTelephony function to hel...
# ask-ai
w
how can I include the BVCTelephony function to help with some of the background noise cancellation?
t
Thanks for reaching out, Arthur. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you want to add the BVCTelephony function for background noise cancellation in LiveKit, here’s a simple way to do it: 1. First, install the Noise Cancellation Package: You’ll need the
livekit-plugins-noise-cancellation
package, which includes the BVCTelephony model. Just run this command:
pip install "livekit-plugins-noise-cancellation~=0.2"
2. Next, import the Noise Cancellation Module: In your Python code, bring in the noise cancellation module like this:
from livekit.plugins import noise_cancellation
3. Then, set up your Room Input Options: When you start your
AgentSession
, make sure to include the BVCTelephony model in the
RoomInputOptions
. This one’s specially tuned for telephony:
Copy code
await session.start(
    agent=agent,
    room=ctx.room,
    room_input_options=room_io.RoomInputOptions(
        noise_cancellation=noise_cancellation.BVCTelephony(),
    ),
)
And that’s it! Following these steps will help you add BVCTelephony noise cancellation to your LiveKit app, making your audio much clearer for telephony scenarios. If you run into any questions, feel free to ask—I’m here to help!
w
Elaborate on what the RoomInputOptions object does?
t
The
RoomInputOptions
object in LiveKit is a handy configuration class that helps you decide how an agent handles input from participants in a room. It gives you detailed control over different parts of input processing, including: • Input Types Configuration: - Text Input: You can turn text input handling on or off. - Audio Input: Manage audio settings like noise cancellation, sample rate, and channel count. - Video Input: Let the agent receive video when you enable this. • Participant Management: Choose which types of participants (like agents or regular users) the agent should listen to for input. • Advanced Audio Options: Includes features like pre-connect audio handling with timeout settings and noise cancellation options such as BVC (Background Voice Cancellation) to boost audio quality. • Session Control: Decide if the session should close when a linked participant disconnects for certain reasons. Here’s a simple example to show you how it works:
Copy code
from livekit.agents import RoomInputOptions
from livekit.plugins import noise_cancellation

# Example configuration
input_options = RoomInputOptions(
    noise_cancellation=noise_cancellation.BVC(),
    participant_kinds=[rtc.ParticipantKind.PARTICIPANT_KIND_AGENT],
    video_enabled=True
)

# Start agent session with the options
await session.start(
    agent=MyAgent(),
    room=ctx.room,
    room_input_options=input_options
)
This object is really helpful for tailoring how your app handles inputs and manages participant interactions in a LiveKit room. If you have any questions or want to explore more options, just let me know!
w
Also, how can I make my agent leave a voicemail if it detects the voicemail answering machine. I am currently following the way it is done in the docs, and it is not working
t
Hey there! If you want your agent to leave a voicemail when it spots an answering machine in LiveKit, here’s a simple way to do it: 1. Set Up Voicemail Detection and Handling: You can use the
detected_answering_machine
tool to leave a message and then hang up. Here’s an example:
Copy code
@function_tool
async def detected_answering_machine(self):
    <http://logger.info|logger.info>(f"detected answering machine for {self.participant.identity}")
    await self.session.generate_reply(
        instructions="Leave a voicemail message letting the user know you'll call back later."
    )
    await asyncio.sleep(0.5)
    await self.hangup()
2. Keep an Eye on Silence: Monitoring silence can help spot voicemail systems. Check this out:
Copy code
import asyncio
import time

SILENCE_THRESHOLD = 5  # seconds

async def monitor_interaction():
    while True:
        if time.time() - user_last_spoke_time > SILENCE_THRESHOLD:
            <http://logger.info|logger.info>("silent for too long! disconnecting")
            try:
                await ctx.room.disconnect()
            except Exception as e:
                logger.exception("Error while ending call")
        await asyncio.sleep(1)
3. Mix It Up for Better Accuracy: Combining silence monitoring with some LLM-based analysis can really boost detection. Here’s how:
Copy code
async def monitor_interaction():
    while True:
        if time.time() - user_last_spoke_time > SILENCE_THRESHOLD:
            <http://logger.info|logger.info>("Attempting LLM-based voicemail detection")
            await ctx.session.generate_reply(
                instructions="Analyzing the call to detect voicemail..."
            )
            detection_result = await llm.detect_voicemail()
            if detection_result:
                await detected_answering_machine()
        await asyncio.sleep(1)
Just a heads up—make sure to tweak the silence threshold and test with different voicemail systems so it works smoothly. And hey, if you have any questions or want a hand with this, I’m here to help! Sources: Agent Testing &amp; Evaluation | livekit/livekit_composite | DeepWiki | Agents telephony integration | LiveKit Docs | How to detect and handle silence during calls | agent.py | Speech &amp; Audio Processing | livekit/livekit_composite | DeepWiki