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.

Terminal
export LIVELY_API_KEY="lv_..."

2. Install the client

Terminal
pip install lively-ai

3. 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.

robot.py
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.

A turn cue
{ "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 }
StatusMeaning
idleNo turn yet in this session.
preparingThe robot has started a reply. No sound has left the server yet.
speakingThe time of the reply’s first sound is known exactly.
endedThe reply’s last audio has been sent.
cancelledThe reply was dropped before any of its sound left the server, usually because the person went on speaking.
interruptedThe person spoke while the reply was playing, and its remaining audio was dropped.
FieldMeaning
turn, revWhich 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_msThe server’s clock when the message was sent, in milliseconds.
text_startedThe reply has its first text: the earliest sign that it will be spoken.
onset_msWhen the reply’s first sound leaves the server. An estimate until onset_exact is true.
segmentsEach 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_msWhen the reply’s last sound leaves the server. Empty until the whole reply is queued.
wordsThe 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.

CueWhat it meansWhen it comesIts lead counts down to
bidGet ready to speakSent at the reply’s first text. The movement should be in place at the first sound.The first sound
holdStay in the speaking postureSent 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
yieldHand the turn overSent when the end of the reply is announced, ahead of the last sound.The last sound
cancelledThe reply will not be spokenUndo the bid at once.Zero
interruptedThe person cut inReturn 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.

mappings.py
# 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.

robot.py
@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