Build an AI roleplay trainer that talks back in real time
Build live roleplay practice with an AI avatar: a buyer or interviewer persona set by your server, objections that hold until the rep earns them, a live score driven by your own functions, and a signed transcript to grade every session.
A roleplay trainer is a live call where the avatar plays the other side: a skeptical buyer, a procurement lead under a budget freeze, or an interviewer working through a hiring loop. Realtime Avatar supplies the live conversation, which is the listening, the turn-taking, the language model's reply, the voice and the face. Your app supplies the scenario, the scoring and the coaching.
The scenario is the session policy
Your connect route decides each drill when it starts the call. instructions holds the persona and its rules of engagement: the objections it raises, what it will and will not concede, the budget it is hiding, how hard it pushes back. context replays up to 32 prior messages, which is where the account background, the job description or the rep's previous attempt at this scenario goes. The browser cannot override either field, so a trainee cannot edit the buyer into an easy one. maxSeconds caps each drill on the platform side.
Realism comes from full duplex
Practice only transfers if the other side behaves like a person. Every call is full duplex, with nothing to configure: the trainee can cut in mid-sentence and the persona stops and can react in character, an "mm-hm" is a backchannel rather than an interruption, and a pause to think is not taken as the end of their turn. One limit is worth knowing: the persona will not start a new sentence over the trainee while they are speaking.
Score it live with tools
Grant clientTools: true at mint, and the persona can call functions you register in the page during the call: move a "convinced" meter, log an objection as handled, or end the drill when the rep asks for the close. They run in your app, so the scoreboard is your state, not the model's. Each has 2.5 seconds to return. Keep scoring writes fast and idempotent: at the deadline the handler's abort signal fires, but a handler that ignores it keeps running and can still write, even though its result is discarded.
Grade every session afterwards
Register a transcript webhook at mint and a signed POST arrives after each call with the full two-sided transcript (segments) and the tool calls the model acted on (tool_calls). Run your own rubric or your own model over it, attribute it with the metadata you set (a trainee id and a scenario id), and store the result. This is the registration from the Tool calling docs:
// Registered on your connect endpoint, server-side only.
session: async ({ avatarId }) => ({
instructions,
transcript: { url: "https://your.app/api/rta/transcript", secret: TRANSCRIPT_SECRET },
// Echoed verbatim, so the keys are yours, except user_id, which
// GET /usage/sessions?endUserId= filters on.
metadata: { user_id: user.id, characterId: avatarId, mode: "video" },
})Verify the signature on the raw request bytes before trusting anything (HMAC-SHA256 over the timestamp and the body, sent as x-rta-signature), and dedupe on session_id, because delivery is at least once. For a coach who wants to watch the call back, recording captures audio, video or audio_video as a server policy: your server decides after getting consent, and the browser cannot switch it on. To end on an exact line, such as telling the trainee their score is ready, sendClosingTurn(text) speaks the text verbatim, never through the model, then ends the session.
Put it in your training app
The client half is one component pointed at your connect route. Use mode="voice" for phone-call practice with no video, or keep the default for a face-to-face meeting.
import { AvatarCall, createProxyClient } from "realtime-avatar/react";
const client = createProxyClient({ proxyUrl: "/api/realtime-avatar" });
<AvatarCall client={client} avatarId={avatarId} />
// Audio only: no video track is requested, so nothing renders and
// nothing decodes.
<AvatarCall client={client} avatarId={avatarId} mode="voice" />What it costs for a team
Assume 100 practice calls a month at 8 minutes each: 800 minutes on air, with up to 3 running at the same time. Under those assumptions the lowest-cost published plan that fits is Developer at $41 a month, about $0.41 per practice call.
| Plan | Subscription | Included minutes | Overage | Estimated total |
|---|---|---|---|---|
| Developer | $24 | 600 | $17 (200 min at $0.085/min) | $41 |
| Starter | $9 | 120 | $64.60 (680 min at $0.095/min) | $73.60 |
| Studio | $119 | 3,000 | $0 | $119 |
The estimate is the monthly subscription plus any minutes beyond the plan's included minutes at its published overage rate. Speech recognition, the language model, the voice and the rendered video are all inside a live minute. It excludes avatar creation, taxes, annual discounts and your own hosting. Try your own volume in the cost calculator, or see every plan on the pricing page.
See it, then build it
The closest working demo is Persuasion games: she dies on an absurd hill and concedes only to an argument she has not heard before. It is the scoring pattern above: on every turn the character reports through one tool how far her conviction has cracked, from 0 to 100, and a second tool declares that you have won, only when a new argument actually defeats her position. It needs a free account, and an account's first 2 minutes of hosted demos are free.
Then read Calls for the session policy and recording, Tool calling for the tool plane and the webhook receiver, and React and React Native to embed the call.
Create a free Sandbox workspace to try it: it includes 480 credits once per account, which is 8 realtime minutes if you spend them all on air, and you can start on an example avatar before making your own. The quickstart takes you from a key to a live call.