Docs
Quickstart
From a lively.ai API key to a robot that talks, listens and moves with its turn.
Draft. The client library is still being designed, so its names on this page may change.
1. Get an API key
Sign up and tell us about your use case. Our team will contact you and issue your key. Set it as an environment variable on the machine that runs your robot.
export LIVELY_API_KEY="lv_..."2. Install the client
pip install lively-ai3. Start a session
A session is one live connection between your robot and lively.ai. The client sends the microphone audio, plays the robot's voice, and calls your function at each turn cue, with the time left before the sound that cue announces. Your function starts one of your robot's own movements.
import asyncio, os
from lively_ai import LivelyAI
# Your mapping: the movement that shows each turn cue.
MOVES = {
"bid": "lift_head", # about to speak
"hold": "keep_posture", # pause inside a reply
"yield": "face_partner", # handing the turn over
"cancelled": "rest", # reply dropped
"interrupted": "rest", # the person cut in
}
async def main():
client = LivelyAI(api_key=os.environ["LIVELY_API_KEY"])
session = client.session(language="en")
@session.on_turn_cue
def move(cue):
# lead_ms: time left until the sound it announces
robot.play(MOVES[cue.name], within_ms=cue.lead_ms)
await session.run(microphone, speaker)
asyncio.run(main())Turn cues
A turn cue is one bot-turn-cue message: the whole state of the robot's current speaking turn. It is sent on every change of that state and again once a second. Its times say when a sound leaves the server, in milliseconds, and they arrive ahead of the sound: the start of a reply, each pause inside it, and its end.
{ "type": "bot-turn-cue", "v": 1, "now_ms": 6582.7,
"turn": 3, "rev": 12, "status": "speaking",
"text_started": true,
"onset_ms": 6103.6, "onset_exact": true,
"segments": [ { "start_ms": 6103.6, "end_ms": 6613.6 },
{ "start_ms": 6939.7, "end_ms": 7499.7 },
{ "start_ms": 7739.7, "end_ms": 8449.7 },
{ "start_ms": 8807.9, "end_ms": 9537.9 } ],
"end_ms": 9537.9,
"words": 12 }| Status | Meaning |
|---|---|
idle | No turn yet in this session. |
preparing | The robot has started a reply. No sound has left the server yet. |
speaking | The time of the reply’s first sound is known exactly. |
ended | The reply’s last audio has been sent. |
cancelled | The reply was dropped before any of its sound left the server, usually because the person went on speaking. |
interrupted | The person spoke while the reply was playing, and its remaining audio was dropped. |
| Field | Meaning |
|---|---|
turn, rev | Which turn this is, and which state of that turn. A message with a lower rev than one already seen for the same turn is out of date. |
now_ms | The server’s clock when the message was sent, in milliseconds. |
text_started | The reply has its first text: the earliest sign that it will be spoken. |
onset_ms | When the reply’s first sound leaves the server. An estimate until onset_exact is true. |
segments | Each unbroken stretch of the reply’s sound, as a start and an end. A gap between two segments is a pause of at least 150 milliseconds. |
end_ms | When the reply’s last sound leaves the server. Empty until the whole reply is queued. |
words | The number of words in the reply’s whole text, once the text is complete. |
From a turn cue to a movement
The client reads each message and tells your function which of five cues it is. Every cue carries lead_ms: the time left, in milliseconds, until the listener hears the sound the cue is timed against. The audio is never held back for the body.
| Cue | What it means | When it comes | Its lead counts down to |
|---|---|---|---|
bid | Get ready to speak | Sent at the reply’s first text. The movement should be in place at the first sound. | The first sound |
hold | Stay in the speaking posture | Sent for a pause inside the reply, while the end of the reply is not yet announced or lies after the pause. | The start of the pause |
yield | Hand the turn over | Sent when the end of the reply is announced, ahead of the last sound. | The last sound |
cancelled | The reply will not be spoken | Undo the bid at once. | Zero |
interrupted | The person cut in | Return to listening at once. | Zero |
Map cues to your robot
A mapping names the movement that shows each cue on one body. It stays on your side: the service does not receive it, and your robot's own controller runs the movement. Showing a cue differently is a change to this table, not to code.
# A humanoid with no neck or eyes: the waist and one arm show the turn.
HUMANOID = {
"bid": "turn_waist_aside_and_raise_arm",
"hold": "keep_posture",
"yield": "lower_arm_and_face_partner",
"cancelled": "rest",
"interrupted": "rest",
}
# An avatar on a screen: mouth, eyes and head show it.
AVATAR = {
"bid": "open_mouth_and_look_away",
"hold": "keep_looking_away",
"yield": "look_at_partner_and_close_mouth",
"cancelled": "rest",
"interrupted": "rest",
}Read the whole state
To time movements yourself, each cue also carries the message it came from.
@session.on_turn_cue
def move(cue):
state = cue.state # the whole bot-turn-cue message
if state["status"] == "speaking" and state["end_ms"] is None:
... # the end of the reply is not announced yet