How to Add a Real-Time Talking Avatar to a Fish Audio Voice Agent, Step by Step
- Published:
- Reading time:
- 11 min
To give a Fish Audio voice agent a real-time face, start a session for your agent with POST /v1/agent/sessions and join the call from your server with LiveKit's Node.js SDK. Publish the visitor's microphone into the call, read the agent's audio track as 16-bit PCM at 24 kHz, and pass each frame to a Talking Avatar Realistic Avatars session with pushAudio(). Fish Audio runs the listening, the LLM and the voice; with the avatar it costs about $0.055 a minute.
How it works
- Your server starts a call with your Fish Audio agent and joins it as the caller with LiveKit's Node.js SDK. The visitor's microphone, streamed from the page as 16-bit PCM at 16 kHz, becomes the call's microphone.
- The agent hears the visitor, answers and speaks: speech recognition, the LLM and the voice all run inside Fish Audio. Your server reads its audio track at 24 kHz and passes every frame to
avatar.pushAudio(). - The agent decides when to yield, and stops sending audio when it does. When the visitor leaves, your server hangs up and closes the avatar, so both stop billing.
Fish Audio's own SDKs are for browsers and phones, but its wire protocol is documented for any LiveKit client, so both API keys stay on your server. Its AI avatar generator makes videos in advance; this gives the agent a face that talks back live. The same setup works with other voice-to-voice models: see our guides for GPT-Live, Gemini Live and AssemblyAI.
What you need
- A Fish Audio agents API key, from Agents → API keys. New accounts get a $5 trial balance, about 140 minutes of web conversation.
- A Talking Avatar account. Sign up to get $1 of free credits; no card is needed.
- Node.js 22 or later, and headphones for your first test.
@livekit/rtc-nodeinstalls a native binary for your platform.
Step 1: Create and publish the Fish Audio agent
The agent holds the prompt, the first message and the voice. Save this as agent.json: it uses Live 3, Fish Audio's full-duplex model, with its Clara voice.
{
"name": "Maya",
"config": {
"prompt": {
"system_prompt": "You are Maya, a warm, helpful guide on Acme's website, talking with a visitor out loud. Keep every answer to one or two short sentences, then let them talk. If you don't know something, say so, and offer to put them in touch with the team.",
"first_message_mode": "fixed",
"first_message": "Hi, I'm Maya. What can I help you with today?"
},
"voice": { "engine": "live3", "voice_id": "clara" }
}
}With FISH_API_KEY set in your shell, create the agent, then set FISH_AGENT_ID to the agent_id in the response and publish it. Sessions only run a published version.
curl -X POST https://api.fish.audio/v1/agent/agents -H "Authorization: Bearer $FISH_API_KEY" -H "Content-Type: application/json" -d @agent.jsoncurl -X POST https://api.fish.audio/v1/agent/agents/$FISH_AGENT_ID/publish -H "Authorization: Bearer $FISH_API_KEY"You can also build it in Fish Audio's console under Agents → New agent; see its quickstart.
Step 2: Add your keys and join the Fish Audio call
Create a Talking Avatar key in the dashboard under API keys → Create key, and put it in a .env file in a new folder, next to the Fish Audio key and agent ID. Neither key ever reaches the browser.
TALKING_AVATAR_API_KEY=tav_…
FISH_API_KEY=…
FISH_AGENT_ID=…
# Keeps LiveKit's debug logs out of your terminal
NODE_ENV=productionInstall our SDK, @livekit/rtc-node to join the call, Express and ws:
npm init -y && npm pkg set type=module && npm install @talkingavatar/sdk @livekit/rtc-node express wsThe server serves the page, starts an avatar for each visitor, joins a Fish Audio call for them and relays the audio both ways.
import { randomUUID } from "node:crypto";
import express from "express";
import { WebSocket, WebSocketServer } from "ws";
import {
AudioFrame, AudioSource, AudioStream, LocalAudioTrack, Room, RoomEvent, TrackKind, TrackPublishOptions, TrackSource,
} from "@livekit/rtc-node";
import { LiveAvatar } from "@talkingavatar/sdk/server";
const { TALKING_AVATAR_API_KEY, FISH_API_KEY, FISH_AGENT_ID } = process.env;
const avatars = new Map(); // conversation ID → LiveAvatar
const MIC_RATE = 16000; // the visitor's microphone, into the call
const VOICE_RATE = 24000; // the agent's voice, out of the call and into the avatar
const app = express()
.use(express.json())
.use(express.static("public"))
.use("/sdk", express.static("node_modules/@talkingavatar/sdk/dist")); // the browser SDK, no bundler needed
// The page's WebRTC route: plays one conversation's avatar.
app.post("/avatar/:id", async (req, res) => {
const avatar = avatars.get(req.params.id);
if (!avatar) return res.status(404).json({ error: "No such conversation" });
try { res.json(await avatar.handleView(req.body)); }
catch (error) { res.status(503).json({ error: error.message }); }
});
const server = app.listen(3000, (error) => {
if (!error) console.log("Open http://localhost:3000"); // on an error, such as the port in use, Node prints it and exits
});
// One WebSocket per visitor: their microphone in, the conversation's state out.
new WebSocketServer({ server, path: "/conversation" }).on("connection", async (browser) => {
const id = randomUUID();
let avatar, room, mic, ended = false;
let micQueue = Promise.resolve(); // microphone frames, in order
const end = (reason) => {
if (ended) return;
ended = true;
if (room) hangUp(room); // Fish Audio's billing stops
avatar?.close(); // and ours
avatars.delete(id);
if (browser.readyState === WebSocket.OPEN) {
browser.send(JSON.stringify({ type: "ended", reason }));
browser.close();
}
};
browser.on("close", () => end("The visitor left"));
// 1. Start the avatar.
try {
avatar = await LiveAvatar.start({ apiKey: TALKING_AVATAR_API_KEY, avatar: "ava7", sampleRate: VOICE_RATE });
} catch (error) {
return end("The avatar didn't start: " + error.message);
}
if (ended) return avatar.close(); // the visitor left while it started
avatars.set(id, avatar);
avatar.on("close", (code) => end("The avatar session ended (" + code + ")")); // 4002: out of credits
browser.send(JSON.stringify({ type: "session", id }));
// 3. The agent's voice, 16-bit PCM at 24 kHz, goes straight to the avatar, which speaks it with lip sync.
const relayVoice = async (track) => {
for await (const frame of new AudioStream(track, { sampleRate: VOICE_RATE, numChannels: 1 })) {
if (ended) break;
avatar.pushAudio(frame.data);
}
};
browser.on("message", async (data, isBinary) => {
// 4. The visitor's microphone, 16-bit PCM at 16 kHz, goes into the call as this server's microphone.
if (isBinary) {
if (!mic || ended) return;
const pcm = new Int16Array(new Uint8Array(data).buffer); // a copy: a ws buffer can start at an odd offset
micQueue = micQueue.then(() => mic.captureFrame(new AudioFrame(pcm, MIC_RATE, 1, pcm.length))).catch(() => {});
return;
}
let message;
try { message = JSON.parse(data.toString()); }
catch { return end("Invalid browser message"); }
if (!message || typeof message !== "object" || Array.isArray(message) || typeof message.type !== "string") return end("Invalid browser message");
if (message.type !== "ready" || room || ended) return;
// 2. The visitor can see and hear the avatar: start the Fish Audio call, and join it from this server.
room = new Room();
room.on(RoomEvent.TrackSubscribed, (track) => {
if (track.kind === TrackKind.KIND_AUDIO) relayVoice(track).catch(() => {}); // the agent's voice
});
room.on(RoomEvent.DataReceived, (payload, participant, kind, topic) => {
if (topic !== "agent-event") return;
const event = JSON.parse(new TextDecoder().decode(payload));
if (event.type === "session.ended") end("The call ended (" + event.reason + ")");
if (event.type === "error") console.error("Fish Audio: " + event.code);
});
room.on(RoomEvent.Disconnected, () => end("The call ended"));
try {
const call = await startCall();
if (call.transport !== "livekit") throw new Error("unsupported transport " + call.transport);
await room.connect(call.livekit_url, call.token, { autoSubscribe: true, dynacast: false });
const source = new AudioSource(MIC_RATE, 1);
const options = new TrackPublishOptions();
options.source = TrackSource.SOURCE_MICROPHONE;
await room.localParticipant.publishTrack(LocalAudioTrack.createAudioTrack("microphone", source), options);
mic = source;
} catch (error) {
return end("Fish Audio: " + error.message);
}
if (ended) return hangUp(room); // the visitor left while the call connected
browser.send(JSON.stringify({ type: "listen", sampleRate: MIC_RATE }));
});
});
// A session token for one call with the agent. Your API key stays on this server.
async function startCall() {
const response = await fetch("https://api.fish.audio/v1/agent/sessions", {
method: "POST",
headers: { Authorization: "Bearer " + FISH_API_KEY, "Content-Type": "application/json" },
body: JSON.stringify({ agent_id: FISH_AGENT_ID }),
});
if (!response.ok) throw new Error("the session request failed (" + response.status + ")");
return response.json(); // session_id, expires_at, transport, livekit_url, token
}
// 5. Ends the call: a hangup on Fish Audio's client-event topic, then leave the room.
async function hangUp(room) {
const hangup = new TextEncoder().encode(JSON.stringify({ type: "user.hangup" }));
await room.localParticipant?.publishData(hangup, { reliable: true, topic: "client-event" }).catch(() => {});
await room.disconnect().catch(() => {});
}
- 1. Starts one avatar session per visitor. It's billed per second until
close(). - 2. Starts the call once the page reports the avatar as live, so the first message isn't spoken to an empty page.
POST /v1/agent/sessionsreturns a LiveKit URL and token for one call. - 3. Reads the agent's audio track at 24 kHz, mono, a rate the avatar takes as it is, so every frame goes straight to
pushAudio(). - 4. Turns the visitor's microphone into the call's microphone track, one 100 ms frame at a time, in order.
- 5. Hangs up with a
user.hangupmessage on theclient-eventtopic. If the agent ends the call itself, itssession.endedevent ends the conversation here too.
ava7 is Maya, one of our library avatars. Any Fish Audio voice works with any avatar, your own custom avatar included.
Step 3: Add the page
LiveAvatarView plays the avatar's video and voice in sync, and a small AudioWorklet streams the microphone as 16-bit PCM at the rate the server asks for, 16 kHz here. Save these three files in public/.
<!doctype html>
<meta charset="utf-8">
<title>Fish Audio with a Talking Avatar</title>
<div id="avatar" style="width: 640px; max-width: 100%; aspect-ratio: 16 / 9; background: #111"></div>
<p>
<button id="start">Talk to Maya</button>
<button id="unmute" hidden>Turn sound on</button>
<span id="status"></span>
</p>
<script type="module" src="/page.js"></script>
public/page.js and public/mic-worklet.js
The same two files in all our voice agent guides: only the server changes between them.
import { LiveAvatarView } from "/sdk/live.js";
const start = document.getElementById("start");
const unmute = document.getElementById("unmute");
const status = document.getElementById("status");
start.onclick = async () => {
start.disabled = true;
// Echo cancellation keeps the avatar's own voice out of the microphone.
let mic;
try {
mic = await navigator.mediaDevices.getUserMedia({ audio: { echoCancellation: true, noiseSuppression: true } });
} catch (error) {
status.textContent = "Microphone unavailable: " + error.message;
start.disabled = false;
return;
}
const socket = new WebSocket(location.origin.replace("http", "ws") + "/conversation");
let view, audio, ready = false;
socket.onmessage = async ({ data }) => {
const message = JSON.parse(data);
if (message.type === "session") {
// Plays the avatar's video and the agent's voice.
view = new LiveAvatarView({
container: document.getElementById("avatar"),
endpoint: "/avatar/" + message.id,
onStatus: (s) => {
status.textContent = s;
unmute.hidden = s !== "muted";
if ((s === "live" || s === "muted") && !ready) {
ready = true;
socket.send(JSON.stringify({ type: "ready" }));
}
},
});
unmute.onclick = () => view.unmute();
view.connect();
}
if (message.type === "listen") {
audio = await streamMicrophone(mic, message.sampleRate, (pcm) => {
if (socket.readyState === WebSocket.OPEN) socket.send(pcm);
});
}
if (message.type === "ended") {
view?.disconnect(); // first, so its "closed" status doesn't replace the reason
status.textContent = message.reason;
}
};
socket.onclose = () => {
view?.disconnect();
view?.video.remove();
audio?.close();
mic.getTracks().forEach((track) => track.stop());
start.disabled = false;
};
};
// Sends the microphone as 16-bit PCM at the agent's input rate, in 100 ms chunks.
async function streamMicrophone(stream, rate, send) {
const context = new AudioContext();
await context.audioWorklet.addModule("/mic-worklet.js");
const node = new AudioWorkletNode(context, "mic", { processorOptions: { rate } });
node.port.onmessage = ({ data }) => send(data);
context.createMediaStreamSource(stream).connect(node).connect(context.destination); // the node outputs silence
await context.resume();
return context;
}
// Resamples the microphone to the agent's input rate and posts 16-bit PCM in 100 ms chunks.
class Mic extends AudioWorkletProcessor {
constructor({ processorOptions }) {
super();
this.step = sampleRate / processorOptions.rate; // input samples per output sample
this.at = 0; // read position; -1 is the previous block's last sample
this.last = 0;
this.chunk = new Int16Array(processorOptions.rate / 10);
this.length = 0;
}
process([input]) {
const samples = input[0];
if (!samples) return true;
while (this.at < samples.length - 1) {
const i = Math.floor(this.at);
const a = i < 0 ? this.last : samples[i];
const value = a + (samples[i + 1] - a) * (this.at - i);
this.chunk[this.length++] = Math.max(-1, Math.min(1, value)) * 0x7fff;
if (this.length === this.chunk.length) {
const out = this.chunk.slice();
this.port.postMessage(out.buffer, [out.buffer]);
this.length = 0;
}
this.at += this.step;
}
this.at -= samples.length;
this.last = samples[samples.length - 1];
return true;
}
}
registerProcessor("mic", Mic);
Step 4: Run it
node --env-file=.env server.jsOpen http://localhost:3000, click Talk to Maya and allow the microphone. Maya greets you with the agent's first message, then listens. Ask her something, and talk over her answer to check that she stops. The avatar starts speaking less than 250 ms after the agent's voice reaches it.
Live 3 yields by itself; on S2.1 Pro or Drama 3, the agent's conversation.interruptible and interruption_sensitivity settings decide how readily the visitor can cut in. For a hard stop, such as a Stop button, publish { "type": "user.interrupt" } on the client-event topic and call avatar.clear(); see our Interruptions docs.
Voices and languages
- Live 3 voices:
clara(the default),nora,harper,patricia,owen,marco,miloandjonah, set invoice.voice_id. - Your clone, or any library voice: set its ID in
voice.voice_id. Live 3 recreates it from a sample, so it sounds close to, not exactly like, the same voice on S2.1 Pro or Drama 3. - Other languages: Live 3 speaks English only. For the others, set
voice.enginetofish_tts,voice.tts_modeltos2.1-proordrama-3, andvoice.speaking_language; see Voice & language. Publish the agent again after each change.
What it costs
Talking Avatar Realistic Avatars cost $0.02 a minute, billed per second, with no subscription; high-volume contracts go as low as $0.005 a minute. Fish Audio charges $0.035 a minute of conversation through 31 December 2026, then $0.07, covering speech recognition, the voice, the basic LLMs, knowledge bases and tool calls (Fish Audio's pricing, checked 24 November 2026).
| At 1,000 minutes a month | Cost |
|---|---|
| Avatar (Talking Avatar Realistic Avatars) | $20 |
| Agent (Fish Audio Voice Agents) | $35 through 31 December 2026, then $70 |
Models outside Fish Audio's basic LLMs are billed by token on top. Don't want to run a server at all? Talking Avatar Voice Agents are complete voice agents on a realistic avatar, set up in our dashboard without code, for $0.06 a minute with the avatar included at no extra cost, and they can speak with a voice from your own Fish Audio account.
Before you go live
- Protect
/conversation. Every connection starts a billed avatar session and a billed Fish Audio call, so put it behind your app's login and limit how many each user can open. - Serve the page over HTTPS. Browsers only allow the microphone on secure pages (localhost is the exception). Keep
echoCancellationon, so the agent doesn't hear itself. - Set spending limits on both sides. In our dashboard, set a monthly limit and auto top-up; a session ends with close code 4002 when credits run out. Fish Audio charges calls to your API credit after its trial balance.
- Plan for the limits. One avatar session lasts up to 3 hours, and each Fish Audio session has its own
max_duration_seconds. A small “Powered by Talking Avatar” watermark shows unless you remove it for $19 a month.
Troubleshooting
- “Fish Audio: the session request failed (401)”
- Fish Audio refused the key. Check
FISH_API_KEY, or create a new key under Agents → API keys. - “Fish Audio: the session request failed (409)”
- The agent has never been published. Sessions only run a published version: run the publish command from step 1, or publish in Fish Audio's Builder.
- “Fish Audio: the session request failed (429)”
- Every concurrent line of your Fish Audio team is in use. Wait and try again; the limit grows with your top-ups.
- The avatar moves but makes no sound
- The browser blocked sound (status
muted). Click Turn sound on, which callsview.unmute().
Methodology
How we wrote this guide
We build Talking Avatar Realistic Avatars, so the avatar side follows our SDK documentation for @talkingavatar/sdk 0.1.0. The Fish Audio side follows its Voice Agents documentation, including the session API and the wire protocol for LiveKit clients, and its pricing page, read on 24 November 2026. On 24 November 2026 we created and published the agent with the commands above, then ran the guide's files as written (on another port) against a live Fish Audio call and avatar session, with Chrome and a recorded voice as the microphone: Maya greeted, Fish Audio transcribed a spoken question and she answered it, answered a second question, and both sessions closed when the page did. Its message flow also has automated tests against a simulated session. The avatar latency figure is our own measurement in production.
Frequently asked questions
Does Fish Audio have a real-time avatar?
No. Fish Audio's AI avatar generator turns a photo and a script into a talking-head video, rendered in advance. To give a Fish Audio agent a face that talks back live, pass the agent's voice to a real-time avatar, as this guide does.
How do I add an avatar to a Fish Audio voice agent?
Create a session for your agent with POST /v1/agent/sessions, join the call's LiveKit room from your server with @livekit/rtc-node, publish the visitor's microphone into it, and read the agent's audio track as 16-bit PCM at 24 kHz. Pass each frame to a Talking Avatar Realistic Avatars session with pushAudio(), and show the avatar on your page with LiveAvatarView.
Do I need another speech-to-text or LLM provider?
No. A Fish Audio agent runs speech recognition, the LLM, the voice and turn-taking itself, and its basic LLMs (Gemini 3.5 Flash Lite, GPT-6 Luna, GPT-5.6 Luna and Gemma 4 26B) are included in its per-minute rate for now. If you want your own model, Fish Audio agents can call a custom OpenAI-compatible endpoint.
Does it work with Fish Audio Live 3?
Yes. New Fish Audio agents start on Live 3, its full-duplex model, which listens while it speaks and decides for itself when to stop. Live 3 speaks English only; for other languages, switch the agent to Fish Audio's text-to-speech engine with S2.1 Pro or Drama 3.
Can I use my own cloned voice?
Yes. Set the agent's voice_id to your clone's ID, or to any voice in Fish Audio's library. On Live 3, Fish Audio recreates the voice from a sample, so it sounds close to, but not exactly like, the same voice on S2.1 Pro or Drama 3.
Does the avatar stop when the visitor interrupts?
Yes. The agent stops speaking when it yields, and stops sending audio; the avatar finishes the fraction of a second it already has, because the audio arrives in real time. For a hard stop, send a user.interrupt message on the client-event topic and call the avatar's clear().
What does a Fish Audio avatar cost?
Fish Audio charges $0.035 a minute of conversation through 31 December 2026, then $0.07, and the avatar is $0.02 a minute: about $0.055 a minute together, then $0.09. Both are billed per second.
Is there a no-code way to use my Fish Audio voice?
Yes. Talking Avatar Voice Agents import voices from your own Fish Audio account with your API key and run the whole agent for $0.06 a minute with the avatar included; Fish Audio bills the speech to your account.
Can the avatar look like me?
Yes. Pick any avatar from our library, or order a custom avatar of a real person, with their consent, for $199 one time. Use its ID in LiveAvatar.start().

About me
Mukul Munjal
Co-founder, Talking Avatar
I'm Mukul Munjal, co-founder of Talking Avatar. I have 7 years of experience in engineering, 3 of them building voice agents, and I handle the optimisation of our voice agents. We built Talking Avatar to give our own AI interviewers a face.
Evaluating tools?
Compare your options
See how the platforms in this article compare on pricing, features and fit.
Anam
LemonSlice
HeyGen LiveAvatar
Realistic avatars from $0.02 a minute, billed per second. No subscription.
Avatar API prices comparedGet API key