cold-agency-22020
09/05/2025, 10:21 AMtall-airline-16756
09/05/2025, 10:21 AMtall-airline-16756
09/05/2025, 10:21 AMcold-agency-22020
09/05/2025, 10:25 AMtall-airline-16756
09/05/2025, 10:26 AMon_track_subscribed is running but no speech is coming through, let’s walk through a few things together to get it sorted:
1. Agent Track Subscription Configuration: Double-check that your agent is set to subscribe to audio tracks using AutoSubscribe.AUDIO_ONLY or AutoSubscribe.SUBSCRIBE_ALL. If it’s set to SUBSCRIBE_NONE, you’ll need to handle the subscription manually.
2. Proper Audio Stream Handling: In your on_track_subscribed callback, make sure you’re creating and iterating over an AudioStream object asynchronously to process those audio frames. Also, keep an eye out for any exceptions that might be quietly stopping the async loop.
3. Source Participant Audio Activity: Check that the participant sending the audio is actually speaking and hasn’t muted their track. If you can, use events like IsSpeakingChanged to keep track of their speaking status.
4. Detailed Logging: It really helps to add some logging around when tracks get subscribed, when audio frames come in, and if any errors pop up. For example, log the participant’s identity and the track SID when a subscription happens, and keep count of the audio frames you receive.
5. Track Subscription Failures: Don’t forget to subscribe to TrackSubscriptionFailed events. These can tell you if there are any subscription hiccups, like network issues.
If you’re still running into trouble, try deploying the agent closer to the media source to cut down on latency. Also, make sure audio isn’t being muted because of silence detection or codec mismatches. Lastly, check your network and any downstream processing to ensure nothing’s accidentally blocking the audio.
Feel free to reach out if you want me to walk you through any of these steps or if you have any other questions — I’m here to help!
Sources: Speech-to-text (STT) integrations | LiveKit Docs | terminal-client/client.py | pkg/loadtester/agentloadtester.go | Getting Help | livekit/livekit_composite | DeepWiki | Speech & Audio Processing | livekit/livekit_composite | DeepWikicold-agency-22020
09/05/2025, 10:27 AMtall-airline-16756
09/05/2025, 10:27 AMAudioStream object. This lets you process audio frames asynchronously, which is super handy.
2. Iterate Over Audio Frames: Use an asynchronous loop to go through each audio frame from the stream. Don’t forget to handle exceptions so nothing slips by unnoticed.
3. Log and Process Frames: It’s a good idea to log the frames you receive for debugging, and then process them as your app needs.
4. Close the Stream: When you’re done, make sure to properly close the stream to free up resources.
Here’s a friendly example to help you get started:
@ctx.room.on("track_subscribed")
def on_track_subscribed(track: rtc.Track, publication: rtc.TrackPublication, participant: rtc.RemoteParticipant):
if track.kind == rtc.TrackKind.KIND_AUDIO:
asyncio.create_task(process_audio(track, participant))
async def process_audio(track: rtc.Track, participant: rtc.RemoteParticipant):
audio_stream = rtc.AudioStream(track)
frame_count = 0
try:
async for event in audio_stream:
if event.frame:
frame_count += 1
logger.debug(f"Received audio frame {frame_count} from {participant.identity}")
# Process the frame here
except Exception as e:
logger.error(f"Error processing audio stream: {e}")
finally:
await audio_stream.aclose()
This should make sure your audio frames are handled nicely, and any hiccups get logged so you can troubleshoot easily. If you want me to walk you through any part or if you have questions, just give me a shout!cold-agency-22020
09/05/2025, 10:28 AMtall-airline-16756
09/05/2025, 10:29 AMtrack_subscribed event is actually firing and showing up in your logs. If it’s not, take a look for muted tracks or subscription hiccups by checking the track_subscription_failed event.
2. Log Frame Reception: Next, double-check that audio frames are coming through by iterating over the AudioStream. Try logging each frame to catch if any are getting silently dropped.
3. Check Auto-Subscribe Setting: Make sure you’re joining the room with auto_subscribe=True. If that’s set to False, you’ll want to add some manual subscription logic for those audio tracks.
4. Validate RoomIO Setup: If RoomIO is in play, confirm that the subscribed_fut future completes successfully—that’s your green light that the initial subscriptions are all set.
5. Inspect Audio Forwarding: In your agent session, double-check that audio_input is properly assigned and that the audio forwarding task is up and running.
6. Handle Pre-Connect Audio: If this applies to you, peek at the TF_PRECONNECT_BUFFER feature flag to see if there’s any buffered audio waiting to be processed before the user joins.
Here’s a little example of how you might log those audio frames:
async def play_audio(audio_stream: rtc.AudioStream):
try:
frame_count = 0
async for event in audio_stream:
if event.frame:
logging.debug(f"Received audio frame ({len(event.frame.data)} bytes)")
frame_count += 1
logging.info(f"Audio stream ended. Total frames received: {frame_count}")
except Exception as e:
logging.error(f"Error during audio stream playback: {e}")
If any of this feels tricky or if you want to chat through the steps, just let me know—I’m here to help!
Sources: livekit-rtc/livekit/rtc/room.py | Subscribing to tracks | LiveKit Docs | livekit-agents/livekit/agents/voice/agent_session.py | terminal-client/client.pycold-agency-22020
09/05/2025, 10:31 AMaudio_input is properly assigned and that the audio forwarding task is up and running.tall-airline-16756
09/05/2025, 10:31 AMaudio_input is set up right and the audio forwarding task is running smoothly. Here’s a simple way to check:
1. Check the audio_input Assignment: First, double-check that the audio_input property in your agent session is assigned properly. Usually, the RoomIO setup handles this automatically, but it’s a good idea to log it and be sure:
if self._input.audio is None:\n logging.error("Audio input is not assigned.")\nelse:\n logging.info("Audio input is properly assigned.")
2. Verify the Audio Forwarding Task: Next, see if the audio forwarding task (_forward_audio_atask) is up and running. Logging its status can help:
if self._forward_audio_atask is None:\n logging.error("Audio forwarding task is not running.")\nelse:\n logging.info("Audio forwarding task is active.")
3. Manually Start the Forwarding Task (if needed): If you find the task isn’t running, make sure it starts once audio_input is assigned. For example:
if self._input.audio and self._forward_audio_atask is None:\n self._forward_audio_atask = asyncio.create_task(self._forward_audio_task())
Following these steps should help you confirm everything’s set up correctly and working as it should. If you hit any snags or want a hand with anything else, just let me know—I’m here to help!cold-agency-22020
09/05/2025, 10:36 AMif self._input.audio is None:\n logging.error("Audio input is not assigned.")\nelse:\n logging.info("Audio input is properly assigned.")tall-airline-16756
09/05/2025, 10:38 AM__init__ or a setup method), this is a great spot to add the check right after you expect the audio input to be assigned.
2. In a Diagnostic Method: You could create a special method just for checking the audio input and call it whenever you need. For example:
def check_audio_input(self):\n if self._input.audio is None:\n logging.error("Audio input is not assigned.")\n else:\n logging.info("Audio input is properly assigned.")
3. Before Starting the Forwarding Task: If you have some logic that kicks off the audio forwarding task, it’s a good idea to run this check first to make sure everything’s ready to go.
If anything’s unclear or you want a hand weaving this into your setup, just give me a shout—I’m here to help!cold-agency-22020
09/05/2025, 10:46 AMtall-airline-16756
09/05/2025, 10:46 AMctx.room.audio_input is actually set. You could add a simple check like this:
if ctx.room.audio_input is None:\n logger.error("Audio input is not assigned.")\nelse:\n logger.info("Audio input is properly assigned.")
2. Keep an Eye on the Audio Forwarding Task: If you’re using a task to forward audio, make sure it only starts once you’ve confirmed the audio input is there. Something like this works well:
if ctx.room.audio_input and self._forward_audio_atask is None:\n self._forward_audio_atask = asyncio.create_task(self._forward_audio_task())
3. Debug Track Subscription: In your on_track_subscribed callback, logging the track details can really help confirm everything’s subscribed properly:
@ctx.room.on("track_subscribed")\ndef on_track_subscribed(track: rtc.RemoteTrack):\n logger.info(f"Subscribed to track: {track.name}, kind: {track.kind}")\n asyncio.create_task(process_track(track))
4. Log When Audio Frames Arrive: Inside your process_track function, it’s helpful to log the audio frames as they come in, so you know they’re being received:
async for audio_event in audio_stream:\n logger.debug(f"Received audio frame: {len(audio_event.frame.data)} bytes")\n stt_stream.push_frame(audio_event.frame)
Adding these checks will give you a clearer picture that the audio input is set up right, the forwarding task is running, and the audio frames are flowing through. If you want to chat more or need any help with this, just let me know—I’m here for you!