Preview: Unity 0.2.0, Godot 0.2.2. Tell us what your game needs at [email protected].
- it listens through the player’s microphone (the server notices when the player stops talking),
- answers in its own voice from where it stands in the world (3D audio),
- moves its mouth with what it says (15 visemes on blend shapes, a jaw, or drawings),
- and calls your game’s functions when the conversation calls for it: sell an item, open a gate, get angry. These are tool calls, set up as “actions”.
Choose your engine
For a game made for a web page (three.js, Phaser, a canvas) use the JavaScript SDK. For another engine, the protocol is a WebSocket, and the core of the Unity package is plain C# with no reference to UnityEngine (how).
Install
- Unity
- Godot
Window > Package Manager > + > Add package from git URL:
Your first talking character
1
Add the agent
Unity: select the character, Add Component > Lokutor > Lokutor Agent.
Godot: add a LokutorAgent child node (put it at the head: the voice comes from there).
2
Paste your API key
From app.lokutor.com. Fine while prototyping; see Shipping before you release.
3
Describe the character
Write who it is in Persona, and pick a Voice (
F1-F5, M1-M5, or a voice from Voices) and Language.4
Press Play and talk
The character greets the player and listens. Headphones recommended.
Which piece does what
Most games mix them: one agent for the character the player is in front of,
LokutorVoice for everybody else. A conversation is the expensive, interesting thing; open one when the player engages and close it when they leave.
Shipping: keep the key on your server
An API key inside a game build can be extracted, whatever you do to hide it, and whoever has it spends your balance. A key is for your server and your own machine. What goes to players is a ticket: it starts withwst_, works anywhere a key does, and expires after ten minutes.
- The game asks your server for one, with whatever already identifies the player (a session, a Steam ticket).
- Your server checks the player, and asks
POST /ws-ticketwith the key in a header. - The game gives the ticket to the agent, which asks for a new one before every connection, reconnections included.
LOKUTOR_API_KEY environment variable. The introductions have a whole ticket request (Unity, Godot).
Microphone permissions
An agent whose microphone cannot start still talks, and hears nothing: there is a warning in the console, and
Mic.IsRunning (Unity) or microphone.running (Godot) is false. Check it after starting the conversation and tell the player. A level meter (Mic.Level, microphone.level) on screen answers the question everyone asks: can it hear me? The clients without a character report audio.microphone_unavailable through their error event.
On Android the Godot microphone asks the player the first time it starts, and begins to hear when they say yes: until then microphone.running is true and microphone.level is 0. Start one on the title screen, as the sample game does, so that the question does not come in the middle of a conversation. A phone’s loudspeaker is beside its microphone: keep mute_mic_while_speaking on unless the player wears headphones.
Echo, barge-in and push to talk
- Mute mic while speaking (on by default) sends silence while the character’s voice can still be heard, through the engine’s buffers and the room’s echo, so laptop speakers cannot make it answer itself. The player cannot interrupt it meanwhile.
- With headphones turn it off: the player can talk over the character, and it stops. Let the player say which they have in the game’s options, or find out: while the character says its first line, compare the loudness of the microphone (
Mic.Level,microphone.level) with that of the voice (VoiceLevel,voice_level()) at delays up to half a second. Not Amused does. - Without headphones and with the microphone open, the character’s own words can come back from the speakers and be taken for the player’s. Godot checks every line it hears against what the character said last (
guard_against_echo, on by default): its own words are dropped,echo_heardis emitted, and mute while speaking turns itself on. On phones and in browsers, whose speakers are beside the microphone, it also waits longer for the room’s echo to fade (700 ms instead of 250). - The microphone is also muted while any other character or written line (
LokutorVoice) is heard. A voice too far away to reach it can be left out (mutesMicrophones,mutes_microphones). - The server does not stop the character for a cough: speech over the character has to last 400 ms, or be a real sentence, to interrupt it (a full second at the opening of a call), and a false alarm never stops the voice (Handling barge-in).
- Push to talk suits loud rooms, streamers and games with several people at one microphone. Sending only what the player means to say also makes recognition better.
- After an interruption the transcript keeps only what was heard, so the character does not believe it said the rest.
Latency
A reply starts in about 306 ms after the player stops when the server had already begun it during their pause, and about 660 ms when not (Latency). What a game can do:- Open the conversation before the player talks: on approaching the character, not on pressing the key.
- Say how it opens in the persona: the character speaks first, and needs a line to say.
- Keep the persona short, and facts in
SetContext. Long prompts are read on every turn. - Ask for short answers in the persona (“one or two short sentences”). A short first sentence is heard sooner.
- Do not make actions wait. A tool call is another trip to the model; return at once and let the game animate.
- Fill the gap with the body.
Thinkingis a state: look up, scratch the beard, say “hm”. A character that reacts feels faster than one that answers quickly and stands still. - Expression tags take their time: a
[laugh]adds two to four seconds to the sentence (Expression tags).
What it costs, and limits
Everything is in Pricing. In short: an agent is $0.042 a minute while it is open, plus the language model, about 5.9¢ a typical minute in all; text to speech is $4.10 per million characters; speech to text $0.0014 a minute; visemes are free. An account has 3 sessions at the same time before its first top-up and 10 after, higher on request. Each open agent, text-to-speech connection or speech-to-text stream is one, across all your players: plan the limit with us before a launch. A session where nobody speaks for five minutes is closed by the server.The same SDK everywhere
The engine pieces (LokutorAgent, LokutorVoice, LokutorLipSync) are only in the game SDKs. The clients under them have the same names and do the same as in JavaScript and Python:
connect and disconnect are open and close in Godot because every Godot object already has methods with those names.
Examples
- Godot: the
godot/folder is a project. Brom’s Forge (demo/forge/) is a blacksmith you talk to and buy from;demo/brom_demo.tscnis the smallest complete example. - Unity: Package Manager > Lokutor Voice Agents > Samples > Talking blacksmith. Add its script to an empty GameObject and press Play.
- Not Amused: how a whole small game is put together around one agent.
- Most Suspicious: one agent that plays every suspect of a murder mystery, in nine languages.
- Play Not Amused in your browser at lokutor.com/games: a Godot web export, made as Games in a web browser explains.
Next
- Game characters: personality, facts, actions, and the animation that makes one feel alive.
- Asset pipeline: modelling a face that can speak.
- Testing without the API: a conversation in your tests, with no key and no network.