Skip to navigation

Audio Decisions in LiveKit

Run a LiveKit voice agent in your terminal and follow how Audio Decisions answers reach its LLM.

Run a LiveKit agent that sends the user’s audio to Hume Audio Decisions with hume.DecisionModel each time the user stops speaking, and puts the answers at the head of the user’s message before the LLM replies. Clone this example to follow along, or fork it as a starting point.

By the end you will have the agent running in your terminal, and you will know how the agent keeps the user’s audio, when it cuts and sends each clip, how the answers reach the LLM, and how to log the user message the LLM receives.

Repositoryhume-audio-decisions-livekit-example on GitHub
Packageslivekit-agents and livekit-plugins-hume on PyPI, version 1.9.1 or later
Python3.10 to 3.14

Prerequisites

  1. Python 3.10 to 3.14, and Git.
  2. A microphone, and headphones so the agent doesn’t hear its own voice.
  3. An API key with Hume Audio Decisions access, from the API keys page of the Hume Platform. Request access on the Decisions API page. See Authentication.
  4. A LiveKit Cloud project. The agent’s speech-to-text, LLM, and text-to-speech run through LiveKit Inference, which uses the project’s API key.
  5. The LiveKit CLI, which runs the agent in console mode: on your machine, with your microphone and speakers, without joining a LiveKit room. Install it with brew install livekit-cli on macOS, or as in Install the CLI on Linux and Windows.

Run the example

Clone the repository and install its dependencies. If you use uv, it needs version 0.13.6 or later and installs the Python version in .python-version for you. If you use pip, first check that python3 --version reports 3.10 to 3.14.

Shell
git clone https://github.com/HumeAI/hume-audio-decisions-livekit-example.git
cd hume-audio-decisions-livekit-example
uv sync

Copy the example environment file.

Shell
cp .env.example .env.local

Set your Hume API key in .env.local, and set the three LiveKit values from your project’s settings in LiveKit Cloud. A value exported in your shell takes precedence over the file.

.env.local
HUME_API_KEY=your_hume_api_key
LIVEKIT_URL=your_livekit_url
LIVEKIT_API_KEY=your_livekit_api_key
LIVEKIT_API_SECRET=your_livekit_api_secret

Start the agent, which introduces itself and then listens. Press q to stop it.

Shell
lk agent console

Speak, then pause. When your turn ends, the agent logs the user message as the LLM receives it: the reading, which holds the answers, then your words. The reading has one signal per decision, named by the decision’s key and followed by its answer: a probability’s value, a choice’s two likeliest options with their probabilities, and a score’s position on its levels. With the example’s three decisions, frustration, speakers, and intelligibility, a line looks like this one, shown without the log prefix.

Terminal
User: ([frustration value=0.82],[speakers one=0.97, two=0.02],[intelligibility value=2.9]) This is the third time I've asked.

When a reading is missing or unexpected, check these causes.

  1. (no reading) on a turn means that turn has no answers. Either Hume Audio Decisions didn’t answer within 2 seconds of you stopping, which logs a warning, or the request failed, which logs an error, or it answered none of the decisions, which logs a warning for each. 401 in that error means the Hume API key is wrong, and 403 means your organization lacks access to Hume Audio Decisions. The agent keeps running without readings until you fix the key.
  2. (no reading) with nothing logged means the turn holds no new speech. Part of your transcript arrived after LiveKit ended the turn, and became a turn of its own.
  3. Most questions need at least 5 seconds of audio. A short reply such as “Yes.” is still sent, since each clip starts half a second before you speak, but its answers are less reliable. See How it sends audio.

How it works

agent.py is the voice agent, and audio_decisions.py holds the AudioDecisions class, which cuts each clip, sends it with hume.DecisionModel, and returns the reading. Each step below links the section of the LiveKit integration guide that explains its pieces.

  1. Choose the decisions

    1. DECISIONS holds the questions, keyed by name, and each name labels its answer in the reading. Each LiveKit decision type is sent as one Hume Audio Decisions primitive and reads differently: a Probability as the estimated share of raters who would say yes, a Choice as its likeliest options with their probabilities, and a Score as a position on its levels, counted from 0. See Map LiveKit decisions to primitives.

    2. A Choice option can carry a description. An empty string sends the option without one.

  2. Explain the reading to the LLM

    1. INSTRUCTIONS is the agent’s system prompt. It shows the LLM the shape of the reading, says what (no reading) means, and tells the LLM not to mention the reading, which is for the LLM only.

    2. Each decision gets a paragraph that says what its value means and the threshold at which the LLM acts on it. See Add it to a voice agent.

  3. Pass the audio through listen

    1. stt_node is the step of the agent that turns the user’s audio into a transcript. The override passes the audio through AudioDecisions.listen on its way to LiveKit’s default stt_node, so speech-to-text gets every frame unchanged. See Add it to a voice agent.

  4. Keep the most recent audio

    1. AudioDecisions takes the session and the decisions, with clip_seconds and wait_limit defaulting to 5 and 2 seconds. hume.DecisionModel() reads HUME_API_KEY and raises ValueError when it is not set. The class listens for three session events: the user’s state, each transcript, and the agent’s state.

    2. listen yields each frame unchanged and keeps the frames that arrived in the last clip_seconds, with their arrival times. When the audio stream ends, it cancels a running request.

  5. Cut a clip at the end of speech

    1. user_state_changed fires a moment after VAD detects the start or end of speech, and speech_timestamp carries when it happened. The first speech of a turn sets the turn’s start.

    2. When the user goes from speaking to listening, the clip is every frame kept since 0.5 seconds before the turn’s first speech, pauses included. A clip shorter than 1 second is not sent, since Hume Audio Decisions rejects it. See How it sends audio.

    3. A newer clip holds the latest speech of the turn, so it cancels a request that is still running. The request runs in a background task, with a timeout that ends at the wait limit, counted from when the user stopped.

  6. Drop speech that never becomes a turn

    1. While the agent can’t be interrupted, such as during its first 3 seconds of speech in a session while echo cancellation warms up, LiveKit by default sends speech-to-text silence in place of the user’s audio. That speech never becomes a turn, so when the agent stops speaking, AudioDecisions drops the speech’s clip and its request, and the next clip starts after it.

    2. A user who is still speaking, or whose words were transcribed, is taking a turn, so their clip is kept.

  7. Send the clip

    1. evaluate sends the clip and the decisions to Hume Audio Decisions, after mixing the audio to mono and resampling it to 16 kHz. max_retry=0 turns off retries, since a retry would outlast the wait limit. See Handle setup and request failures.

    2. Every failure logs and returns (no reading), so the reply goes ahead without answers: a timeout as a warning, an error status with the status and the Hume Audio Decisions error message, and any other failure, such as a failed DNS lookup, in full.

    3. A decision that Hume Audio Decisions could not answer is logged as a warning, and the other answers become the reading.

  8. Return the reading

    1. reading waits for the turn’s running request, which gives up at the wait limit, and returns (no reading) when the turn has none. It also clears the turn’s start, so no clip joins speech from before and after the agent’s reply.

    2. _format_reading writes a probability’s value with two decimals, a score’s position with one, and a choice’s two likeliest options with their probabilities. See How the answers reach the LLM.

  9. Add the reading to the turn

    1. LiveKit calls on_user_turn_completed before the LLM replies. The agent awaits the reading, puts it at the head of the user’s message, and logs the message as the LLM receives it. See Check that answers reach the LLM.

  10. Start the session

    1. The session’s speech-to-text, LLM, and text-to-speech models run through LiveKit Inference.

    2. Preemptive generation is off. A preemptive reply starts on the transcript before the reading is in the user’s message, and LiveKit discards it when the message changes. See Add it to a voice agent.

    3. The session gets one AudioDecisions, which the agent receives, and the agent greets the user once the session starts.

import logging
from collections.abc import AsyncGenerator, AsyncIterable
from dotenv import load_dotenv
from livekit import rtc
from livekit.agents import (
Agent,
AgentServer,
AgentSession,
JobContext,
ModelSettings,
TurnHandlingOptions,
cli,
inference,
llm,
stt,
)
from audio_decisions import AudioDecisions
load_dotenv(".env.local")
logger = logging.getLogger("agent")
DECISIONS: dict[str, llm.Decision] = {
"frustration": llm.Probability("Does the speaker sound frustrated?"),
"speakers": llm.Choice(
"How many distinct speakers are there?",
# An option's description is optional.
options={"one": "", "two": "", "three_or_more": ""},
),
"intelligibility": llm.Score(
"How much of the speaker's speech can a listener understand?",
levels=["Almost none", "Some", "Most", "All"],
),
}
INSTRUCTIONS = """\
You are a helpful assistant in a voice conversation. Your responses will be spoken \
aloud, so avoid emojis, bullet points, or other formatting that can't be spoken. Keep \
your responses brief.
Each user message starts with a reading of how the user sounded, in parentheses, such \
as ([frustration value=0.12],[speakers one=0.98, two=0.01],[intelligibility \
value=2.8]). The user's words follow it. The user never sees the reading, so don't \
mention it or its numbers. (no reading) means there is none for that message.
frustration is the estimated share of raters who would say the user sounded \
frustrated, from 0 to 1. If it is 0.6 or above, acknowledge once that the user sounds \
frustrated, then focus on helping.
speakers is how many distinct voices were in the user's audio, with how likely each \
count is. If two or three_or_more is 0.5 or above, someone near the user may be \
talking too: answer only what the user asked you, and if the words seem meant for \
someone else, ask whether they're talking to you.
intelligibility is how much of the user's speech a listener could understand, as a \
position on a scale from 0 (almost none) to 3 (all). It is a measure, not a \
confidence, so a low value is a real reading. If it is below 1.5, the transcription \
may be wrong: say back what you heard and ask the user to confirm or repeat it before \
acting on it.
"""
class Assistant(Agent):
def __init__(self, audio_decisions: AudioDecisions) -> None:
super().__init__(instructions=INSTRUCTIONS)
self._audio_decisions = audio_decisions
def stt_node(
self, audio: AsyncIterable[rtc.AudioFrame], model_settings: ModelSettings
) -> AsyncGenerator[stt.SpeechEvent, None]:
return Agent.default.stt_node(
self, self._audio_decisions.listen(audio), model_settings
)
async def on_user_turn_completed(
self, turn_ctx: llm.ChatContext, new_message: llm.ChatMessage
) -> None:
reading = await self._audio_decisions.reading()
new_message.content = [f"{reading} {new_message.text_content}"]
logger.info("User: %s", new_message.text_content)
server = AgentServer()
@server.rtc_session()
async def entrypoint(ctx: JobContext) -> None:
session = AgentSession[None](
stt=inference.STT(model="assemblyai/assemblyai-stt-3-7-realtime-agent"),
llm=inference.LLM(model="google/gemma-4-31b-it"),
tts=inference.TTS(
model="fishaudio/s2.1-pro",
voice="fa4c9eb3dccc4806b382b40d61c6b10a",
),
turn_handling=TurnHandlingOptions(
turn_detection=inference.TurnDetector(),
# A preemptive reply starts before the reading is in the caller's message,
# and LiveKit discards it when the message changes.
preemptive_generation={"enabled": False},
),
)
audio_decisions = AudioDecisions(session, DECISIONS)
await session.start(agent=Assistant(audio_decisions), room=ctx.room)
await session.generate_reply(instructions="Introduce yourself to the user.")
if __name__ == "__main__":
cli.run_app(server)

Adapt it to your agent

  1. Add it to an existing agent. Follow Install and then Add it to a voice agent in the LiveKit integration guide. The two sections cover what this example sets up: the plugin, audio_decisions.py, and the changes in Assistant and entrypoint.
  2. Change the decisions. Edit or add decisions in DECISIONS. See Map LiveKit decisions to primitives and Writing questions.
  3. Describe each decision to the LLM. Give each decision in DECISIONS a paragraph in INSTRUCTIONS that says what its value means, as the example does.
  4. Set your own thresholds. The thresholds in INSTRUCTIONS are the example’s. Set yours from your own calls, as in Setting thresholds, once your decisions and their order are final, since adding, removing, or reordering decisions can change the other answers.
  5. Change the clip length or the wait limit. Pass clip_seconds or wait_limit to AudioDecisions. See Choose which audio to send and Set the wait limit in code.
  6. Use other models. Any LiveKit Inference model, or a LiveKit plugin for a provider you have an account with, can replace the models in entrypoint.
  7. Act on answers outside the LLM. _ask has every answer in response.results before it formats the reading. Act on them there in your backend, such as alerting a supervisor.
  8. Serve users in LiveKit rooms. Console mode serves only your own machine. To reach users in a room, run the agent in one of LiveKit’s other startup modes.

Next steps