i do self hosting livekit with sip. It works sever...
# ask-ai
f
i do self hosting livekit with sip. It works several days ago but now when i call , the agent and caller get in the same room but the agent doesnt say nor hear anything.Therefore it disconnected .What can be the problem when i didnt make any changes to the code
t
Thanks for reaching out, Huy. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
I understand how frustrating it can be when SIP calls in your self-hosted LiveKit setup connect to the same room but don’t transmit audio properly. Let’s walk through some common reasons this might happen and how to address them: • Media Ports or Network Issues: It’s important to make sure that the UDP ports for RTP traffic are open and accessible. Also, double-check your
ListenIP
and
LocalNet
settings in your SIP service configuration to ensure they’re correctly set. • Jitter Buffer or RTP Misconfiguration: Please verify that
EnableJitterBuffer
is enabled (set to
true
) in your SIP configuration. Taking a look at your logs for any RTP-related errors can provide helpful clues too. • Agent-to-Agent Speech Detection: Make sure your agents are set up to detect and process speech from other agents in the same room by updating the
RoomInputOptions
. • Unsubscribed Audio Tracks: Sometimes, there can be delays in subscribing to audio tracks. Checking your logs for any subscription delays and ensuring all participants are fully connected before expecting audio can make a difference. • Audio Timeout Interruptions: During testing, try simulating audio activity to prevent media timeouts that might interrupt the audio flow. If you’d like, we can dig deeper together by reviewing your SIP and agent configurations or examining any specific errors in your logs, such as
cannot create opus decoder
or
media timeout
. Just let me know how I can assist you further—I’m here to help! Sources: LiveKit Docs | pkg/sip/room.go | How to Enable Agent-to-Agent Speech Detection in LiveKit | CHANGELOG.md | SIP troubleshooting guide | LiveKit Docs
f
if i use server using amazone etc does opening a new port affect in any way
t
I'd be happy to help you with this! Opening a new port on your cloud server, like AWS, generally won’t impact LiveKit SIP functionality as long as the essential SIP ports stay properly set up and accessible. These important ports include: • Port 5060 (TCP/UDP): Used for SIP signaling. • Port 5061 (TCP): Used for SIP over TLS. • Port range 10000–20000 (UDP): Handles RTP media traffic. It’s a good idea to double-check that your AWS security group rules explicitly allow traffic on these ports. Sometimes, if UDP traffic on port 5060 or the RTP range is blocked, it can cause issues with SIP functionality. Once you’ve made any changes, testing the SIP functionality will help ensure everything is running smoothly. Please feel free to reach out if you need any more guidance—I’m here to help! Sources: Ports and firewall | LiveKit Docs | Secure trunking | LiveKit Docs | Running LiveKit on AWS | Running LiveKit on AWS | Running LiveKit on AWS
f
if i create my own custom class for stt llm tts how can i check the time for each step
t
Measuring the time taken for each step in your custom STT, LLM, and TTS class can be really insightful, and I’d be happy to guide you through some approaches: • Built-in Metrics: LiveKit offers native metrics like
STTMetrics
,
LLMMetrics
, and
TTSMetrics
that provide useful details such as duration, time to first token (TTFT), and time to first byte (TTFB). You can subscribe to
metrics_collected
events to easily access these metrics. • Custom Timing: If you’re working on a custom implementation, a great way is to wrap your processing logic with timestamp checks using
time.time()
or
asyncio.get_event_loop().time()
. Logging or emitting the time difference for each step can really help track performance. • Advanced Observability: For a more comprehensive view, enabling OpenTelemetry allows trace-based observability of the entire agent lifecycle, including custom nodes. This is fantastic for capturing execution flow and spotting any performance bottlenecks. If you’d like, I’m here to help you implement timing in a specific node or assist with integrating a monitoring tool. Just let me know! Sources: metrics/send-metrics-to-3p/send_metrics_to_3p.py | Pipeline nodes and hooks | LiveKit Docs | Logs, metrics, and telemetry | LiveKit Docs | agents/src/metrics/base.ts
f
i have use time for the other 2 that i use cutom code how do i do it with stt when it is build in session = AgentSession( stt = google.STT( model="telephony", languages="ja-JP", _spoken_punctuation_=False, ),
t
I'm glad you're looking into measuring the time taken for built-in STT processing in LiveKit when using Google STT in an
AgentSession
. You can make use of the handy built-in
STTMetrics
, which includes a
duration
field showing the time (in seconds) it took to create the transcript after processing the audio input. You can find these metrics through the
session.metrics
object. For streaming STT, since the
duration
metric doesn’t quite apply, a good approach is to set up some custom timing by: • Tracking when audio chunks are sent to the STT service. • Noting the timestamps when you receive transcript responses (whether interim or final). • Calculating the time difference between the audio input and the transcript response to understand the processing latency. If you’d like, I’m here to help you implement this timing logic or guide you through accessing the
STTMetrics
in your session. Just let me know! Sources: Community & Support | livekit/livekit_composite | DeepWiki | livekit-agents/livekit/agents/voice/agent.py | Logs, metrics, and telemetry | LiveKit Docs
f
i meant for do i use the stt metrics can you show me in codes
t
Here is an example of how you can use
STTMetrics
to measure the time taken for STT processing in your `AgentSession`:
Copy code
from livekit import AgentSession
from livekit.stt import google

# Initialize the AgentSession with Google STT
session = AgentSession(
    stt=google.STT(
        model="telephony",
        languages="ja-JP",
        spoken_punctuation=False,
    )
)

# Define a callback to handle STT metrics
def on_stt_metrics(metrics):
    print(f"STT processing duration: {metrics.duration} seconds")
    print(f"Audio duration: {metrics.audio_duration} seconds")

# Subscribe to the metrics_collected event for STT
session.stt.on("metrics_collected", on_stt_metrics)

# Start the session (example usage)
session.start()

# Perform your operations here...

# Stop the session when done
session.stop()
In this example: • The
on_stt_metrics
function is called whenever STT metrics are collected. • You can access the
duration
(time taken for processing) and
audio_duration
(length of the input audio) from the
metrics
object. • Ensure that the session is started and stopped properly to collect metrics during its lifecycle. If you have any questions or need a bit more help with this, please feel free to ask. I’m here to support you every step of the way!
f
i dont see it printing
t
It seems like the STT metrics aren’t showing up, and I’m here to help you figure out what might be going on. Here are a few common reasons and some steps you can try: • Missing Metrics Listener: First, please double-check that the
metrics_collected
event listener is set up correctly on your STT instance. Here’s a quick example:
Copy code
def on_stt_metrics(metrics):
    print(f"STT processing duration: {metrics.duration} seconds")
    print(f"Audio duration: {metrics.audio_duration} seconds")

session.stt.on("metrics_collected", on_stt_metrics)
• STT Not Processing Audio: Make sure that audio is actually being captured and sent properly to the STT service. • Google STT Configuration: It’s also a good idea to confirm that your Google Cloud credentials are set up and authenticated correctly. • Logging Configuration: Finally, check that your logging level is configured to show the metrics. For example:
Copy code
import logging
logging.basicConfig(level=logging.INFO)
If you’d like, I’m happy to walk through these steps with you or help troubleshoot further. Just let me know! Sources: metrics/metrics_tts.py | Logs, metrics, and telemetry | LiveKit Docs | Google Cloud STT plugin guide | LiveKit Docs
f
on the livekit official docs A log_metrics helper function is also provided to format logging output for each metric type. from livekit.agents import metrics, MetricsCollectedEvent ... @session.on("metrics_collected") def _on_metrics_collected(ev: MetricsCollectedEvent): metrics.log_metrics(ev.metrics)
t
You're absolutely right! LiveKit offers a handy
log_metrics
helper function that makes formatting and logging metrics for each type super easy. Let me walk you through how you can use it in your code:
Copy code
from livekit.agents import metrics, MetricsCollectedEvent

# Set up the session with Google STT
session = AgentSession(
    stt=google.STT(
        model="telephony",
        languages="ja-JP",
        spoken_punctuation=False,
    )
)

# Use the log_metrics helper to log all collected metrics
@session.on("metrics_collected")
def _on_metrics_collected(ev: MetricsCollectedEvent):
    metrics.log_metrics(ev.metrics)

# Start the session
session.start()

# Perform your operations here...

# Stop the session when done
session.stop()
This will take care of logging all metrics, including the STT ones, in a neat and formatted way. If you have any questions or need a bit more help, just let me know—I’m here for you!