how can i connect to the room locally when running...
# ask-ai
s
how can i connect to the room locally when running this example? https://github.com/livekit/agents/blob/0.x/examples/text-to-speech/openai_tts.py
t
Thanks for reaching out, Wolfgang. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
To connect to a LiveKit room locally using the
openai_tts.py
example, follow these steps: 1. Ensure you have the required dependencies installed:
Copy code
livekit-agents>=0.12.20
livekit-plugins-openai>=0.12.3
python-dotenv~=1.0
2. In the script, the connection to the room is managed with the following lines:
Copy code
await job.connect(auto_subscribe=AutoSubscribe.SUBSCRIBE_NONE)
publication = await job.room.local_participant.publish_track(track, options)
await publication.wait_for_subscription()
3. To run the example locally, use the CLI command at the end of the script:
Copy code
if __name__ == "__main__":
    cli.run_app(WorkerOptions(entrypoint_fnc=entrypoint))
This will start the agent, connect to a LiveKit room, and play the text-to-speech audio using OpenAI's TTS service with the "nova" voice. Sources: Tree View: | dse-workbench
s
when running the script I don't see the first log message: logger.info("starting tts example agent")
t
The log message
<http://logger.info|logger.info>("starting tts example agent")
is part of the
entrypoint
function in the
openai_tts.py
script. It should appear when the TTS example agent starts running, before initializing the OpenAI TTS service with the "nova" voice. If you are not seeing this log message, please ensure that: • The script is being executed correctly and reaches the
entrypoint
function. • The logging level is set to display
INFO
level messages. You can check or configure the logging settings in your script. If the issue persists, let me know, and I can assist further. Sources: Tree View: | dse-workbench
s
I'm running the script like
python <file_name> dev
. should i be running it differently?
t
To run the
openai_tts.py
script, you should use the following command:
Copy code
python <file_name>
Ensure that: • You have installed all the required dependencies as listed in the script's documentation or requirements file. • Your environment variables are properly set up, as the script uses
load_dotenv()
to load them from a
.env
file. Running the script with additional arguments like
dev
may not be necessary unless explicitly required by your setup. If you still encounter issues, let me know, and I can assist further. Sources: Tree View: | dse-workbench
s
when running
python <file_name> start
the last log message I see is
job process initialized
t
The log message
job process initialized
indicates that the job process has been successfully initialized. This message is logged in the
proc_main
function after the initialization of the job process. If this is the last log message you see, it suggests that the script might not be proceeding beyond this point. Please ensure that: • All required dependencies are installed and up-to-date. • Your environment variables are correctly configured, as the script relies on them for proper execution. • You are running the script with the correct command (
python <file_name>
or
python <file_name> start
if explicitly required). If the issue persists, let me know, and I can assist further in diagnosing the problem. Sources: livekit.agents.ipc.job_proc_lazy_main API documentation
s
how are jobs assigned to workers ?
t
Jobs in LiveKit are assigned to workers using a balanced distribution system: 1. Jobs are distributed in a round-robin manner, ensuring each job is assigned to only one worker at a time. 2. If a worker fails to accept a job within a set timeout, the job is reassigned to another available worker. 3. In LiveKit Cloud, geographic affinity is used to prioritize matching users and workers that are geographically closest, minimizing latency. 4. Within a region, job distribution is uniform across workers. 5. Worker availability is determined by the
load_fnc
and
load_threshold
parameters in the
WorkerOptions
configuration. By default, workers stop accepting new jobs when their CPU utilization exceeds 75%. If you have further questions or need clarification, feel free to ask! Sources: Deploying to production | LiveKit Docs | Deployment and scaling | LiveKit Docs
s
when is a job assigned? what triggers it?
t
A job assignment in LiveKit is triggered when a user connects to a room. Here's how the process works: 1. Worker Registration: Your agent code registers itself as a "worker" with the LiveKit server and waits on standby for requests. 2. Job Request: When a user connects to a room, the LiveKit server sends a request to an available worker. The worker accepts the request and starts a new process to handle the job. 3. Job Execution: The job is initiated by the
entrypoint
function in your agent code. 4. Session Close: By default, the room is automatically closed when the last non-agent participant leaves. If you have additional questions or need further clarification, feel free to ask! Sources: Worker lifecycle | LiveKit Docs
s
so in the example how can I get a token to connect to the room locally?
t
I'm sorry, but I don't have the information you need at the moment. If you would like a member of the LiveKit team to respond, please ask your question in one of the other channels.
s
is there an example of a user connecting to a room somewhere in the docs?