what is the difference between await self.ctx.roo...
# ask-ai
c
what is the difference between await self.ctx.room.disconnect() and await self.api.room.remove_participant( api.RoomParticipantIdentity( room=self.room.name, identity=self.participant.identity, ) ) ? which actually ends the call?
t
Thanks for reaching out, Sai. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
The key differences between the two methods in LiveKit are as follows: •
await self.ctx.room.disconnect()
: This is a client-side action where the participant voluntarily leaves the room. It is typically called by the participant themselves, and on some platforms, it is automatically triggered when the application exits. If not explicitly called, the participant will be removed after a timeout period (e.g., 15 seconds after application termination). •
await self.api.room.remove_participant()
: This is a server-side action used to forcibly disconnect a participant from the room. It triggers a
Disconnected
event for the participant with a specific reason. However, this method does not invalidate the participant's token, meaning they could potentially rejoin unless additional measures are taken (e.g., using short TTL tokens or not issuing new tokens). In terms of ending the call, both methods can achieve this, but the context differs. The first is participant-initiated, while the second is server-initiated. Sources: Connecting to LiveKit | LiveKit Docs | Managing participants | LiveKit Docs
c
if I have a sip trunk twilio, does await self.api.room.remove_participant() end the call?
t
Unfortunately, I couldn't find specific information on whether
await self.api.room.remove_participant()
ends a SIP trunk call with Twilio in LiveKit. This might depend on how the SIP integration is configured and managed within your setup. If you need further assistance, I recommend consulting the LiveKit documentation on SIP integration or reaching out to a LiveKit specialist for more detailed guidance.
c
await self.api.room.remove_participant() is server initiated? so if the client is taking web call they would call await self.ctx.room.disconnect()?
t
Yes,
await self.api.room.remove_participant()
is a server-initiated action, typically used to forcibly disconnect a participant from the room. On the other hand, if the client is taking a web call, they would use
await self.ctx.room.disconnect()
to voluntarily leave the room. This is a client-side action initiated by the participant themselves.
c
how to get transcript with timestamps after room is deleted
t
Unfortunately, I couldn't find specific information on how to retrieve a transcript with timestamps after a room is deleted in LiveKit. This functionality might depend on how transcripts are stored or managed in your setup. If transcripts are being recorded or stored externally, you may need to check the storage location or service where they are saved. For further assistance, consulting the LiveKit documentation or a LiveKit specialist might be helpful.
c
how to do a callback after room is deleted?
t
I'm sorry, I couldn't find specific information on how to implement a callback after a room is deleted in LiveKit. This might involve setting up a webhook or monitoring events related to room deletion, depending on your system's configuration. For detailed guidance, I recommend consulting the LiveKit documentation or reaching out to a LiveKit specialist.
c
is there no on room deleted thing?
t
Yes, LiveKit provides a way to handle room deletion events. When a room is deleted using the
DeleteRoom
API, participants in that room are automatically disconnected, and they receive a
Disconnected
event with the reason
ROOM_DELETED
. You can use this disconnection reason in your application code to trigger any necessary actions or callbacks when a room is deleted. Sources: Connecting to LiveKit | LiveKit Docs | ROOM_DELETED
c
yes. give me code to capture that disconnected event python
t
Unfortunately, I couldn't find specific Python code examples for capturing the
Disconnected
event with the
ROOM_DELETED
reason in LiveKit. However, you can typically listen for disconnection events in your client SDK and check the reason code to handle this scenario. For detailed implementation, I recommend referring to the LiveKit Python SDK documentation or reaching out to a LiveKit specialist for assistance.
c
give me code
t
Here is a basic example of how you might capture a
Disconnected
event in Python using the LiveKit SDK:
Copy code
from livekit import Room, RoomEvent

# Define a callback function to handle room events
def on_room_event(event):
    if isinstance(event, RoomEvent.Disconnected):
        if event.reason == "ROOM_DELETED":
            print("The room was deleted, and the participant has been disconnected.")

# Create a room instance and set up the event listener
room = Room()
room.on_event = on_room_event

# Connect to the room (replace with your connection details)
await room.connect("your_server_url", "your_token")

# Keep the application running to listen for events
await room.run()
Note: This is a general example and may need adjustments based on the specific LiveKit Python SDK you are using. Please refer to the SDK documentation for exact implementation details.
c
but if room is deleted will on_room_event get called before room is deelted?
t
When a room is deleted using the
DeleteRoom
API, the
Disconnected
event with the reason
ROOM_DELETED
is triggered for participants before the room is fully deleted. This allows the client to handle the disconnection event appropriately before the room ceases to exist. So yes, the
on_room_event
callback will be called before the room is completely deleted.
👍 1
c
How do I stream live audio?
t
To stream live audio in LiveKit, you can use the following approaches depending on your platform and requirements: • Using LocalAudioTrackRecorder (Swift SDK): The
LocalAudioTrackRecorder
class captures audio from a local track and streams it as a data stream in a selected format. This can then be sent to other participants using
ByteStreamWriter
. • Using AudioByteStream (Agents JS): The
AudioByteStream
class is available for handling audio byte streams in LiveKit Agents. • Working with AudioTracks (JS Client SDK): The JS Client SDK provides
AudioTrack
types for handling audio streams. • Using RemoteAudioTrack (JS Client SDK): For receiving audio from remote participants, you can use the
RemoteAudioTrack
class. For detailed implementation, please refer to the LiveKit documentation for your specific SDK. Sources: AudioByteStream | LiveKit Agents | AudioTrack | LiveKit JS Client SDK - v2.8.1 | RemoteAudioTrack | LiveKit JS Client SDK - v2.8.1 | LocalAudioTrackRecorder | Documentation
c
Give code on how to stream live audio from python agent to iOS app
t
To stream live audio from a Python agent to an iOS app using LiveKit, you can follow these steps: 1. Create a Python Voice Agent: `lk app create --template=voice-pipeline-agent-python my-recording-app`This command sets up a voice agent template for your Python backend. 2. Configure the Agent: Set up your agent with a name for dispatching:
Copy code
if __name__ == "__main__":
    cli.run_app(
        WorkerOptions(
            entrypoint_fnc=entrypoint,
            prewarm_fnc=prewarm,
            agent_name="inbound-agent",
        ),
    )
3. Run the Agent: `python3 agent.py dev`This starts your Python agent, which can now handle audio streams. 4. Stream Audio to iOS: On the iOS side, use the LiveKit iOS SDK to connect to the room and receive the audio stream. The SDK provides tools to handle audio tracks and play them in your app. LiveKit's framework ensures low-latency audio streaming between the Python agent and the iOS app. For detailed implementation, refer to the LiveKit documentation for both the Python agent and iOS SDK. Sources: LiveKit Docs | Accepting incoming calls | LiveKit Docs | LiveKit
c
Is it real time tho
t
Yes, LiveKit is designed for real-time audio and video streaming. The framework uses WebRTC for low-latency connections, ensuring that audio streamed from your Python agent to the iOS app is delivered in real time. This makes it suitable for applications like live communication, voice agents, and interactive experiences.