Skip to main content
Preview, version 0.2.0. Tell us what your game needs at [email protected].
The Lokutor package makes a character of your game a voice agent: it listens through the player’s microphone, answers in its own voice from where it stands, moves its mouth, and calls your game’s functions. It needs no other packages.

What you need

  • Unity 2021.3 or newer, Mono or IL2CPP.
  • A Lokutor API key, from app.lokutor.com.
  • A microphone. Headphones while you try it, so the character does not hear itself.
It works on Windows, macOS, Linux, Android and iOS. WebGL is not supported yet (its builds have neither System.Net.WebSockets nor the Microphone class): for a web page use the JavaScript SDK.

Install

1

Add the package

Window > Package Manager > + > Add package from git URL:
2

Ask for the microphone on mobile

Add a microphone usage description (iOS: Player Settings > Microphone Usage Description).

Your first character

1

Add the component

Select your character and Add Component > Lokutor > Lokutor Agent. It comes with an AudioSource, and the voice comes from where the GameObject is, so the head is a good place.
2

Paste your API key

In Api Key. Leave it empty to use LokutorAgent.DefaultApiKey or the LOKUTOR_API_KEY environment variable, which keeps the key out of your scenes. Never ship a game with a key inside: see Shipping.
3

Say who it is

Write Persona, and pick a Voice (F1-F5, M1-M5, or a voice from your dashboard) and a Language. auto follows the language the player speaks.
4

Press Play and talk

The character greets the player and listens.
Or import the Talking blacksmith sample (Package Manager > Lokutor Voice Agents > Samples): add its script to an empty GameObject, paste your key and press Play.

Events

onCharacterSaid carries what the character is about to say, with the expression tags the voice performs ([laugh]); LokutorApi.StripTags takes them out.

Start and stop

A conversation is billed while it is open (Pricing), so open it when the player engages. Turn off Start On Awake and:
While it is open you can change who the character is and what it knows:
When the connection drops it is opened again by itself (onReconnecting, then onReconnected). The new session does not remember the old one: the facts of SetContext are sent again, what was said is not. If it cannot be opened, or the server ends it, onConversationEnded says why.

Microphone

Mute Mic While Speaking (on) sends silence while the character’s voice can still reach the microphone, so laptop speakers do not make it interrupt itself, and while another character or a LokutorVoice is heard, so that it does not answer them. Turn it off when players wear headphones and you want them to be able to interrupt. Muted = true is the player’s own mute button. Microphone Device picks another microphone.

The voice

It plays through the AudioSource: its mixer group, distances and effects are yours. Spatial Voice places it in 3D; Pitch shifts it up or down.

A dashboard agent

To use an agent built in the dashboard (prompt, voice, knowledge, tools), set Agent Id and empty Persona, Voice and Language: whatever you leave in them overrides the dashboard. SetContext needs a persona in the game, because a dashboard prompt cannot be extended from it.

Shipping

A key inside a game build can be extracted. Have your server trade it for a ticket that lasts ten minutes (POST /ws-ticket) and give the agent that. TicketProvider is called on the main thread before every connection, reconnections included:
Return an empty string when there is no ticket: the conversation ends with an error instead of waiting. The same property exists on LokutorVoice.

Next