Set up talking characters
Goal
Get a game ready for talking characters (AI NPCs with a persona and a voice, running on Convorcher, the hosted conversation service): the relay that keeps the API key on the dev server, and the page side that plays the voice, moves the face, shows subtitles and a talk box, and passes everything to the game as conversation-events. Done once per game; then Write a character's story and Talk to a character.
Files you will edit
vite.config.tssrc/main.ts
Steps
The key. The API key from your Gameable account (Account → Developers) goes in
.env.local, never insrc/:GAMEABLE_API_KEY=aos_.... In the Gameable sandbox it is already set: skip this step.The relay.
vite.config.tsturns ontalk(the third-person template already does):tsplugins: [gameable({ talk: true })],The dev and preview servers then serve
<base>talk/(the conversation and the microphone's transcription), with the key kept on the server, and everysrc/<id>.story.yamlis a character the game can talk to.The page. In
src/main.ts, afterbindFeaturesand beforecreateEngineAdapter:tsimport { talkingCharacters } from 'gameable/conversation'; const talk = talkingCharacters({ audio: engine.get('audio'), characters, // the character bridge: the face moves with the voice emit: (event) => adapter.events.push(event), names: { guard: 'Brannoc' }, // optional: the name the talk box shows for an id (else the id) });and in
createEngineAdapter's options, hand the game's conversation commands to it:tsconversation: (command) => talk.handle(command),While a conversation is open,
talkingCharactersshows a talk box at the bottom of the page: the character's subtitles, a field to type in (typing never moves the player) and a microphone button (push to talk).
Verify
npm run devlogsgameable: talk: the relay is at /talk/(under the base).- Without the key it logs
talk needs GAMEABLE_API_KEY, and the game still runs.
See also
- Talking characters — how the relay, the page and the game fit
- Write a character's story — the next step: a character to talk to
- Talk to a character — walking up and talking