tall-mechanic-24834
02/15/2025, 5:37 AMgray-monkey-83525
02/15/2025, 5:37 AMtall-mechanic-24834
02/15/2025, 5:37 AMgray-monkey-83525
02/15/2025, 5:37 AMVoicePipelineAgent
with various plugins for VAD, STT, LLM, and TTS. However, there are a few points to consider:
1. Plugin Initialization: Ensure that the plugins (Silero VAD, Deepgram STT, Google LLM, and Cartesia TTS) are correctly initialized with the necessary API keys and configurations. The os.getenv
function is used to fetch environment variables, so make sure these are set correctly in your environment.
2. Room Connection: The code attempts to connect to a Livekit room using a URL and token. Ensure that these are valid and that the Livekit server is accessible.
3. Error Handling: The code includes error handling for connection timeouts and other exceptions. Make sure to check the logs for any specific error messages that might indicate what needs to be fixed.
4. Assistant Lifecycle: The VoicePipelineAgent
is started and managed within an asynchronous loop. Ensure that the start
, cleanup
, and disconnect
methods are correctly implemented and called.
If you need more detailed guidance or encounter specific errors, please let me know!
Sources:
- https://docs.livekit.io/python/livekit/agents/pipeline/pipeline_agent.html#args
- https://docs.livekit.io/python/livekit/agents/pipeline/index.html#args 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.tall-mechanic-24834
02/15/2025, 5:38 AMgray-monkey-83525
02/15/2025, 5:39 AMLIVEKIT_URL
and LIVEKIT_TOKEN
environment variables are correctly set and valid. These are crucial for establishing a connection to the Livekit server.
2. Network Connectivity: Verify that there are no network issues preventing the connection to the Livekit server. This includes checking firewall settings and ensuring that the server is reachable.
3. Increase Timeout: Consider increasing the timeout duration in the asyncio.wait_for
call to allow more time for the connection to be established, especially if network latency is a factor.
4. Error Handling: Ensure that any exceptions are properly caught and logged to provide more context on what might be causing the event loop to close.
Would you like more detailed guidance on any of these steps?
Sources:
- https://livekit-users.slack.com/archives/C07FRP66XGE/p1730288245.597009
- https://livekit-users.slack.com/archives/C07FY8WHGPM/p1731772038.705719 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.tall-mechanic-24834
02/15/2025, 5:42 AMgray-monkey-83525
02/15/2025, 5:42 AMLIVEKIT_URL
and LIVEKIT_TOKEN
environment variables are correctly set. These are crucial for establishing a connection to the Livekit server. Double-check that the token is valid and not expired.
2. Network Connectivity: Check for any network issues that might be preventing the connection to the Livekit server. This includes verifying firewall settings and ensuring that the server is reachable from your network.
3. Increase Timeout: Consider increasing the timeout duration in the asyncio.wait_for
call to allow more time for the connection to be established, especially if network latency is a factor.
4. Check Server Logs: If you have access to the Livekit server logs, check for any errors or warnings that might indicate why the connection is failing.
5. Debugging: Add more logging to capture detailed information about the connection attempt. This can help identify where the process is failing.
Would you like more detailed guidance on any of these steps?
Sources:
- LiveKit Room Connection 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.tall-mechanic-24834
02/15/2025, 5:48 AMgray-monkey-83525
02/15/2025, 5:48 AMjwt
library. Typically, JWT tokens are encoded and decoded using jwt.encode()
and jwt.decode()
, not jwt.dumps()
. Verify that your code is using the correct methods for handling JWT tokens.
2. Token Generation: Double-check the process of generating the token. Ensure that the token is correctly signed and includes all necessary claims such as room
, identity
, and permissions
. The token should be a valid JWT string.
3. Environment Variables: Verify that the LIVEKIT_TOKEN
environment variable is set correctly and contains a valid JWT token. You can use online JWT decoders to inspect the token and ensure it is correctly formatted.
4. Server Logs: Since the server response status is 200 and the response is OK, it indicates that the server is reachable. However, the token issue might be preventing a successful connection. Check the server logs for any additional error messages related to token validation.
Would you like more detailed guidance on any of these steps?
Sources:
- LiveKit Authentication
- JWT Library Usage 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.tall-mechanic-24834
02/15/2025, 5:50 AMConnecting to room...
Timeout waiting for room connection
error putting to queue: Event loop is closed
What's the correct way to set up the room connection and event loop for a voice assistant?"
1. "Can you share a complete, working example of a voice assistant using:
• Cartesia for TTS
• Deepgram for STT
• Google Gemini for LLM
• Silero for VAD"gray-monkey-83525
02/15/2025, 5:50 AMAccessToken
class from the LiveKit Python SDK. Here's a basic example:
from livekit import AccessToken, VideoGrant
import os
def generate_token(room_name, identity):
api_key = os.getenv('LIVEKIT_API_KEY')
api_secret = os.getenv('LIVEKIT_API_SECRET')
if not api_key or not api_secret:
raise ValueError("API key and secret must be set in environment variables.")
grant = VideoGrant(room_join=True, room=room_name)
token = AccessToken(api_key, api_secret, identity=identity)
token.add_grant(grant)
return token.to_jwt()
# Example usage
room_name = "example_room"
identity = "user123"
token = generate_token(room_name, identity)
print("Generated Token:", token)
2. Setting Up Room Connection and Event Loop
Ensure that your event loop is correctly set up and that the room connection is properly handled. Here's a basic setup:
import asyncio
from livekit import rtc
async def connect_to_room(url, token):
room = rtc.Room()
@room.on("connected")
def on_connected():
print("Connected to room")
@room.on("disconnected")
def on_disconnected():
print("Disconnected from room")
await room.connect(url, token)
return room
async def main():
url = os.getenv('LIVEKIT_URL')
token = os.getenv('LIVEKIT_TOKEN')
if not url or not token:
raise ValueError("LiveKit URL and token must be set in environment variables.")
room = await connect_to_room(url, token)
try:
while True:
await asyncio.sleep(1)
except KeyboardInterrupt:
print("Shutting down...")
finally:
await room.disconnect()
if __name__ == "__main__":
asyncio.run(main())
3. Complete Voice Assistant Example
Here's a complete example using the specified plugins:gray-monkey-83525
02/15/2025, 5:51 AMimport os
import asyncio
from dotenv import load_dotenv
from livekit.plugins import cartesia, deepgram, google, silero
from livekit.agents.pipeline import VoicePipelineAgent
from livekit import rtc
# Load environment variables
load_dotenv()
async def main():
# Initialize plugins
vad = silero.VAD.load()
stt = deepgram.STT()
llm = google.LLM(
model="gemini-pro",
api_key=os.getenv('GOOGLE_API_KEY')
)
tts = cartesia.TTS(
model="sonic-english",
voice="c2ac25f9-ecc4-4f56-9095-651354df60c0",
speed=0.8,
emotion=["curiosity:highest", "positivity:high"]
)
# Create room with event handling
room = rtc.Room()
connection_ready = asyncio.Event()
@room.on("connected")
def on_connected():
print("Room connection established")
connection_ready.set()
@room.on("disconnected")
def on_disconnected():
print("Room disconnected")
connection_ready.clear()
print("Connecting to room...")
await room.connect(
url=os.getenv('LIVEKIT_URL'),
token=os.getenv('LIVEKIT_TOKEN')
)
# Wait for connection to be ready
try:
await asyncio.wait_for(connection_ready.wait(), timeout=10.0)
print(f"Connected to room: {room.name}")
# Create and start voice assistant
assistant = VoicePipelineAgent(
vad=vad,
stt=stt,
llm=llm,
tts=tts
)
print("Starting voice assistant...")
await assistant.start(room)
print("Assistant started successfully")
# Keep the connection alive
while True:
if not connection_ready.is_set():
print("Connection lost!")
break
await asyncio.sleep(1)
except asyncio.TimeoutError:
print("Timeout waiting for room connection")
except KeyboardInterrupt:
print("\nShutting down...")
except Exception as e:
print(f"Error: {e}")
finally:
if hasattr(assistant, 'cleanup'):
await assistant.cleanup()
elif hasattr(assistant, 'close'):
await assistant.close()
if room and hasattr(room, 'disconnect'):
await room.disconnect()
print("Cleanup completed")
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
print("\nInterrupted by user")
except Exception as e:
print(f"Fatal error: {e}")
Ensure all environment variables are set correctly, and the necessary API keys are available. This setup should help you resolve the JWT errors and connection timeouts.
Sources:
- https://livekit-users.slack.com/archives/C07FVFGAUKX/p1733152587.089089
- https://docs.livekit.io/agents/voice-agent/voice-pipeline/ 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.tall-mechanic-24834
02/15/2025, 5:56 AMgray-monkey-83525
02/15/2025, 5:56 AMroom
, identity
, and permissions
.
2. Incorrect API Key/Secret: Double-check that the API key and secret used to generate the token are correct and match those configured on your LiveKit server.
3. Token Expiration: Ensure that the token has not expired. Tokens typically have an expiration time, and if the token is expired, the server will reject it.
4. Permissions: Verify that the token includes the correct permissions for the room you are trying to access. The token should have a VideoGrant
with roomJoin
set to true
and the correct room
specified.
5. Room Name: Ensure that the room name specified in the token matches the room you are trying to connect to. Any mismatch will result in a 401 error.
6. Server Configuration: Check the server configuration to ensure that it is set up to accept connections with the provided token.
Would you like more detailed guidance on any of these steps?
Sources:
- LiveKit Authentication
- LiveKit Token Generation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.tall-mechanic-24834
02/15/2025, 5:58 AMgray-monkey-83525
02/15/2025, 5:58 AMroom_name
and identity
used in the token generation match exactly with what you are trying to connect to. Any mismatch will result in a 401 error.
- Verify that the VideoGrants
are correctly set. The room_join
permission should be True
, and the room
should match the room you are connecting to.
2. Token Format:
- Ensure that the token is correctly formatted as a JWT. The token.to_jwt()
method should be used to generate the JWT string. In your code, it seems like there might be a formatting issue with <http://token.to|token.to>_jwt()
. It should be token.to_jwt()
.
3. Environment Variables:
- Double-check that the LIVEKIT_API_KEY
, LIVEKIT_API_SECRET
, LIVEKIT_URL
, and LIVEKIT_TOKEN
environment variables are correctly set and match the configuration on your LiveKit server.
4. Token Verification:
- When decoding the token for verification, ensure that you are using the correct library and method. The jwt.decode()
function should be used with the options={"verify_signature": False}
parameter for debugging purposes only.
5. Server Configuration:
- Ensure that the LiveKit server is configured to accept connections with the provided token. Check the server logs for any additional error messages related to token validation.
Here's a corrected version of the token generation code:
# token_generator.py
from livekit import api
import os
from dotenv import load_dotenv
load_dotenv()
def generate_token(room_name, identity):
api_key = os.getenv('LIVEKIT_API_KEY')
api_secret = os.getenv('LIVEKIT_API_SECRET')
if not api_key or not api_secret:
raise ValueError("API key and secret must be set in environment variables.")
# Create token
token = api.AccessToken(api_key, api_secret)
# Set identity and name
token.identity = identity
token.name = "RoleShape AI Assistant"
# Set video grants
token.grants = api.VideoGrants(
room=room_name,
room_join=True,
can_publish=True,
can_subscribe=True,
can_publish_data=True
)
return token.to_jwt()
if __name__ == "__main__":
try:
# Generate token
room_name = "roleshape-room"
identity = "roleshape-assistant"
token = generate_token(room_name, identity)
print("\nGenerated Token:")
print(token)
# Verify token contents
import jwt
decoded = jwt.decode(token, options={"verify_signature": False})
print("\nToken contents:")
for key, value in decoded.items():
print(f"{key}: {value}")
except Exception as e:
print(f"Error: {e}")
gray-monkey-83525
02/15/2025, 5:58 AMtall-mechanic-24834
02/15/2025, 6:04 AMgray-monkey-83525
02/15/2025, 6:04 AMVideoGrant
with roomJoin
set to True
and the correct room
specified.
- Verify that the token is a valid JWT and is not expired. You can use a JWT decoder to inspect the token and ensure it contains the expected claims.
2. API Key and Secret:
- Double-check that the API key and secret used to generate the token are correct and match those configured on your LiveKit server.
3. Room Name and Identity:
- Ensure that the room_name
and identity
used in the token generation match exactly with what you are trying to connect to. Any mismatch will result in a 401 error.
4. Environment Variables:
- Verify that the LIVEKIT_API_KEY
, LIVEKIT_API_SECRET
, LIVEKIT_URL
, and LIVEKIT_TOKEN
environment variables are correctly set and match the configuration on your LiveKit server.
5. Server Configuration:
- Check the server configuration to ensure that it is set up to accept connections with the provided token. Review the server logs for any additional error messages related to token validation.
If you have verified all the above and the issue persists, consider regenerating the token and ensuring all parameters are correctly set.
Would you like more detailed guidance on any of these steps?
Sources:
- LiveKit Authentication
- LiveKit Token Generation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.tall-mechanic-24834
02/15/2025, 6:08 AMgray-monkey-83525
02/15/2025, 6:08 AMVideoGrant
is correctly set when generating the token. The api.AccessToken
class should be used to add the VideoGrant
with the necessary permissions.
2. Correct Method Usage:
- The method token.to_jwt()
should be used to convert the token to a JWT string. It seems there might be a formatting issue with <http://token.to|token.to>_jwt()
. It should be token.to_jwt()
.
3. Setting Video Grants:
- Use the VideoGrant
class to set the video permissions explicitly. Here's how you can modify your token generation code:
# token_generator.py
from livekit import api
import os
from dotenv import load_dotenv
load_dotenv()
def generate_token(room_name, identity):
api_key = os.getenv('LIVEKIT_API_KEY')
api_secret = os.getenv('LIVEKIT_API_SECRET')
if not api_key or not api_secret:
raise ValueError("API key and secret must be set in environment variables.")
# Create token
token = api.AccessToken(api_key, api_secret)
# Set identity and name
token.identity = identity
token.name = "RoleShape AI Assistant"
# Set video grants
video_grant = api.VideoGrant(
room=room_name,
room_join=True,
can_publish=True,
can_subscribe=True,
can_publish_data=True
)
token.add_grant(video_grant)
return token.to_jwt()
if __name__ == "__main__":
try:
# Generate token
room_name = "roleshape-room"
identity = "roleshape-assistant"
token = generate_token(room_name, identity)
print("\nGenerated Token:")
print(token)
# Verify token contents
import jwt
decoded = jwt.decode(token, options={"verify_signature": False})
print("\nToken contents:")
for key, value in decoded.items():
print(f"{key}: {value}")
except Exception as e:
print(f"Error: {e}")
4. Verification:
- After generating the token, use a JWT decoder to verify that the token contains the expected video grants and other claims.
By ensuring the correct usage of the VideoGrant
class and the to_jwt()
method, you should be able to generate a token with the necessary video permissions.
Sources:
- LiveKit Authentication 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.tall-mechanic-24834
02/15/2025, 6:11 AMgray-monkey-83525
02/15/2025, 6:11 AMVideoGrant
is being imported or used. Let's address this by ensuring the correct import and usage:
1. Correct Import: Make sure you are importing VideoGrant
from the correct module. It should be imported from livekit
.
2. Usage: Ensure that you are using the VideoGrant
class correctly when setting the grants for the token.
Here's how you can modify your code to correctly import and use `VideoGrant`:
# token_generator.py
from livekit import AccessToken, VideoGrant
import os
from dotenv import load_dotenv
load_dotenv()
def generate_token(room_name, identity):
api_key = os.getenv('LIVEKIT_API_KEY')
api_secret = os.getenv('LIVEKIT_API_SECRET')
if not api_key or not api_secret:
raise ValueError("API key and secret must be set in environment variables.")
# Create token
token = AccessToken(api_key, api_secret)
# Set identity and name
token.identity = identity
token.name = "RoleShape AI Assistant"
# Set video grants
video_grant = VideoGrant(
room=room_name,
room_join=True,
can_publish=True,
can_subscribe=True,
can_publish_data=True
)
token.add_grant(video_grant)
return token.to_jwt()
if __name__ == "__main__":
try:
# Generate token
room_name = "roleshape-room"
identity = "roleshape-assistant"
token = generate_token(room_name, identity)
print("\nGenerated Token:")
print(token)
# Verify token contents
import jwt
decoded = jwt.decode(token, options={"verify_signature": False})
print("\nToken contents:")
for key, value in decoded.items():
print(f"{key}: {value}")
except Exception as e:
print(f"Error: {e}")
Key Points:
- Import: Ensure VideoGrant
is imported directly from livekit
, not livekit.api
.
- Token Generation: Use add_grant()
to add the VideoGrant
to the token.
This should resolve the error and allow you to generate a token with the necessary video permissions. If you encounter further issues, please let me know!
Sources:
- https://docs.livekit.io/concepts/authentication/
- https://docs.livekit.io/home/get-started/authentication/ 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.tall-mechanic-24834
02/15/2025, 6:12 AMgray-monkey-83525
02/15/2025, 6:12 AMAccessToken
class is not being imported correctly from the livekit
module. This could be due to a few reasons:
1. Incorrect Module Path: Ensure that the livekit
module is installed and accessible in your Python environment. You can verify this by checking your installed packages.
2. Correct Import Path: The AccessToken
and VideoGrant
classes should be imported from the livekit.api.access_token
module, not directly from livekit
.
Here's how you can modify your import statement to correctly import AccessToken
and `VideoGrant`:
# token_generator.py
from livekit.api.access_token import AccessToken, VideoGrant
import os
from dotenv import load_dotenv
load_dotenv()
def generate_token(room_name, identity):
api_key = os.getenv('LIVEKIT_API_KEY')
api_secret = os.getenv('LIVEKIT_API_SECRET')
if not api_key or not api_secret:
raise ValueError("API key and secret must be set in environment variables.")
# Create token
token = AccessToken(api_key, api_secret)
# Set identity and name
token.identity = identity
token.name = "RoleShape AI Assistant"
# Set video grants
video_grant = VideoGrant(
room=room_name,
room_join=True,
can_publish=True,
can_subscribe=True,
can_publish_data=True
)
token.add_grant(video_grant)
return token.to_jwt()
if __name__ == "__main__":
try:
# Generate token
room_name = "roleshape-room"
identity = "roleshape-assistant"
token = generate_token(room_name, identity)
print("\nGenerated Token:")
print(token)
# Verify token contents
import jwt
decoded = jwt.decode(token, options={"verify_signature": False})
print("\nToken contents:")
for key, value in decoded.items():
print(f"{key}: {value}")
except Exception as e:
print(f"Error: {e}")
Key Points:
- Correct Import Path: Use from livekit.api.access_token import AccessToken, VideoGrant
to import the necessary classes.
- Verify Installation: Ensure that the livekit
package is installed in your environment.
This should resolve the import error and allow you to generate tokens correctly. If you encounter further issues, please let me know!
Sources:
- LiveKit API Documentation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.tall-mechanic-24834
02/15/2025, 6:16 AMgray-monkey-83525
02/15/2025, 6:16 AMtall-mechanic-24834
02/15/2025, 6:23 AMgray-monkey-83525
02/15/2025, 6:23 AMVoiceAssistant
class is not available in the livekit.agents
module. This could be due to a few reasons:
1. Module Update: The VoiceAssistant
class might have been renamed or moved in a newer version of the LiveKit SDK. It's important to check the latest documentation or release notes for any changes.
2. Correct Class Name: In recent updates, the VoiceAssistant
class might have been replaced by VoicePipelineAgent
or another class. You should verify the correct class name in the latest LiveKit documentation.
3. Installation: Ensure that you have the latest version of the LiveKit SDK installed. You can update the package using pip.
Here's how you can address the issue:
1. Check Documentation: Refer to the LiveKit Agents Documentation to verify the correct class name and usage.
2. Update SDK: Make sure you have the latest version of the LiveKit SDK installed. You can update it using:
pip install --upgrade livekit-agents
3. Use VoicePipelineAgent
: If VoiceAssistant
has been replaced, try using VoicePipelineAgent
instead. Here's how you might modify your code:
import os
from dotenv import load_dotenv
from livekit.plugins import cartesia, deepgram, google, silero
from livekit.agents.pipeline import VoicePipelineAgent
# Load environment variables
load_dotenv()
# Initialize plugins
vad = silero.VAD.load()
stt = deepgram.STT()
llm = google.LLM(
model="gemini-2.0-flash-exp",
temperature=0.8,
api_key=os.getenv('GOOGLE_API_KEY')
)
tts = cartesia.TTS(
model="sonic-english",
voice="c2ac25f9-ecc4-4f56-9095-651354df60c0",
speed=0.8,
emotion=["curiosity:highest", "positivity:high"]
)
# Create voice assistant
assistant = VoicePipelineAgent(
vad=vad,
stt=stt,
llm=llm,
tts=tts
)
if __name__ == "__main__":
import sys
assistant.run(sys.argv[1] if len(sys.argv) > 1 else "dev")
By following these steps, you should be able to resolve the import error and run your voice assistant. If you encounter further issues, please let me know!
Sources:
- LiveKit Agents Documentation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.tall-mechanic-24834
02/15/2025, 6:36 AMgray-monkey-83525
02/15/2025, 6:36 AMnpm install livekit-client
- Create a Simple Web Page: Set up a basic HTML page with a script to connect to the LiveKit room using the token.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>LiveKit Web Interface</title>
</head>
<body>
<h1>LiveKit Web Interface</h1>
<div id="video-container"></div>
<script type="module">
import { Room } from 'livekit-client';
async function connectToRoom() {
const url = 'wss://your-livekit-server-url';
const token = 'YOUR_GENERATED_TOKEN';
const room = new Room();
await room.connect(url, token);
console.log('Connected to room:', room.name);
// Handle video and audio tracks
room.on('trackSubscribed', (track, publication, participant) => {
if (track.kind === 'video') {
const videoElement = track.attach();
document.getElementById('video-container').appendChild(videoElement);
}
});
}
connectToRoom().catch(console.error);
</script>
</body>
</html>
3. Run the Web Interface: Open the HTML file in a web browser. Ensure that the url
and token
variables are set to your LiveKit server URL and the generated token, respectively.
4. Test the Connection: Once the web interface is running, it should connect to the LiveKit room using the provided token. You should see video and audio streams if everything is set up correctly.
By following these steps, you should be able to connect to your LiveKit room using a web interface. If you encounter any issues, ensure that the token is valid and that the server URL is correct. Let me know if you need further assistance!
Sources:
- LiveKit JavaScript SDK Documentation 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.tall-mechanic-24834
02/15/2025, 6:45 AMgray-monkey-83525
02/15/2025, 6:45 AMLIVEKIT_URL
and LIVEKIT_CLIENT_TOKEN
environment variables are correctly set. If they are not set or are empty, the os.getenv()
function will return None
, which could lead to type errors.
2. Logging Setup: The line logging.basicConfig(level=<http://logging.INFO|logging.INFO>)
seems to have an incorrect syntax. It should be logging.basicConfig(level=logging.INFO)
without the angle brackets and URL-like syntax.
3. Token and URL: Verify that the token and URL are valid strings. If either is None
or an incorrect type, it could cause the error.
4. Debugging: Add print statements to check the values of url
and token
before the room.connect()
call to ensure they are correctly set.
Here's a revised version of your code with these considerations:
# test_client.py
import asyncio
from livekit import rtc
import os
from dotenv import load_dotenv
import logging
# Set up logging
logging.basicConfig(level=logging.INFO)
load_dotenv()
async def main():
room = rtc.Room()
@room.on("connected")
def on_connected():
print("\n:large_green_circle: Connected to room!")
if hasattr(room, 'local_participant'):
print(f"Connected as: {room.local_participant.identity}")
@room.on("participant_connected")
def on_participant_connected(participant):
print(f":bust_in_silhouette: Participant joined: {participant.identity}")
@room.on("track_subscribed")
def on_track_subscribed(track, publication, participant):
print(f":microphone: Subscribed to {track.kind} track from {participant.identity}")
# Retrieve environment variables
url = os.getenv('LIVEKIT_URL')
token = os.getenv('LIVEKIT_CLIENT_TOKEN')
# Debugging: Print URL and token
print(f"URL: {url}")
print(f"Token: {token}")
print("\nConnecting to room...")
await room.connect(url=url, token=token)
print("\nConnected! You can now speak to the assistant.")
print("Press Ctrl+C to exit")
try:
while True:
await asyncio.sleep(1)
except KeyboardInterrupt:
print("\nDisconnecting...")
finally:
await room.disconnect()
print("Disconnected")
if __name__ == "__main__":
try:
asyncio.run(main())
except KeyboardInterrupt:
print("\nInterrupted by user")
except Exception as e:
print(f"Error: {e}")
gray-monkey-83525
02/15/2025, 6:46 AM