All writing

I Built a Real-Time Voice Coach for Age of Empires 2

How I wired ElevenLabs, Tauri, and a vision model into TrebuCoach, a voice coach that watches my screen and talks me through Age of Empires 2 matches.

A live Age of Empires 2 match with a TrebuCoach voice-coaching line overlaid

Work in progress. I have better videos and demos than the ones in here, but I wanted to start sharing this now anyway.

Here's the scene I wanted to build for. You're eleven minutes into a ranked Age of Empires 2 match, scrambling to click up to Castle Age. Your scout just bumped into the enemy base, and you completely missed that two of your villagers have been standing next to a tree doing nothing for the last thirty seconds. Then a calm voice in your headphones says:

"Two idle villagers, put them back on wood until you have 12. And you've found him: he's massing archers, so start thinking skirmishers."

I didn't type anything or pause the game. The voice just noticed what I missed, the way a friend watching your screen on Discord would.

That voice is called TrebuCoach, a trebuchet welded to a coach, because Age of Empires 2 players can't resist a trebuchet pun. And I built it.

A little while back I wrote about spending a weekend building a macOS driver so I could fly Microsoft Flight Simulator with a borrowed joystick. This is apparently becoming a series: Leo gets obsessed with a game and builds something slightly unreasonable to play it better. I'm a software engineer and CTO at Pento AI, so I spend my weekdays building AI products and my weekends pointing that same energy at whatever game is eating my evenings. Lately, that's been a 27-year-old real-time strategy game.

Why Age of Empires 2 needs a nag, not a grandmaster

Video: quick match recap just to show that I crushed it - Look mom, I won!

If you've never played it: Age of Empires 2 came out in 1999 and somehow refused to die. It got a Definitive Edition in 2019, still has an active competitive ladder, and runs in-person tournaments like Red Bull Wololo with real prize pools and packed arenas.

Picture: Wololo Londinium tournament championship in 2026, one of the largest in-person Age of Empires tournaments, hosted by Red Bull
Picture: Wololo Londinium tournament championship in 2026, one of the largest in-person Age of Empires tournaments, hosted by Red Bull

The loop looks simple on paper. You start with a Town Center and a handful of villagers, gather wood, food, gold, and stone, climb through four Ages (Dark, Feudal, Castle, Imperial), and build an army to wreck the other player before they wreck you. It's chess where both sides move at once, the clock doesn't stop, and you're also responsible for farming the wheat.

What hooks you is how many plates you have to spin at the same time. Keep every villager working. Keep the Town Center producing. Don't get "housed" (hitting the population cap because you forgot to build houses). Spend your resources instead of letting them pile up. Scout the map and react to what the enemy is making. Drop any one of those for thirty seconds and you'll spend the next ten minutes paying for it.

Screenshot: a typical Age of Empires 2 match with the resource HUD, idle-villager indicator, and minimap highlighted
Screenshot: a typical Age of Empires 2 match with the resource HUD, idle-villager indicator, and minimap highlighted

After way too many ladder games, my opinion is that the gap between a 900-Elo player and a 1400-Elo player is rarely flashy micro. It's the boring stuff: keeping the Town Center running, not floating 600 wood while stuck under the population cap, hitting Feudal on time instead of two minutes late, and reacting once your scout spots the enemy. None of that is hard to understand. It's just hard to remember while forty other things are competing for your attention.

A strong friend watching your stream doesn't need to out-think the game for you. Most of the time they just call out the obvious thing you forgot: "Town Center's idle," "you're floating gold," "click up to Castle." That felt narrow enough to actually build.

The constraint: no live-match API

Here's the catch. Age of Empires 2 has no official public real-time API for live matches, nothing like Dota 2's Game State Integration. Replay files get written to disk, and spectator tools like CaptureAge hook into the game directly, neither of which I wanted to rely on or risk breaking during ranked play.

For a live match, all the state a macro coach cares about sits in one place: the HUD pixels on screen.

So the design comes down to reading the screen the way a human does:

  1. Capture the game window on a timer.
  2. Parse the HUD into structured game state.
  3. Speak up only when something changes that's worth interrupting you for.

The architecture

Diagram: the three pieces (a Tauri desktop app, a vision model, and an ElevenLabs voice agent) and how a screenshot flows between them
Diagram: the three pieces (a Tauri desktop app, a vision model, and an ElevenLabs voice agent) and how a screenshot flows between them

Three off-the-shelf pieces do the heavy lifting, and the project is mostly the wiring between them:

  • Tauri desktop app (capture and orchestration). This has to run natively so it can screenshot a specific window in the background, keep API keys in the Rust backend where outbound requests happen rather than in the frontend WebView, and handle global hotkeys while Age of Empires has full focus. Tauri gave me a small native binary with a Rust core and a plain web UI on top.
  • Vision model (the eyes). On a configurable tick, set to 5000ms in my setup, the app captures the Age of Empires window, scales it down, and sends the frame to Google Gemini. I also wired OpenRouter in as an option so I can swap models. Instead of asking for a chatty description, the prompt requests a fixed-shape structured output: resources, population, current Age, villager and idle-villager counts, in-game clock, and whether the enemy is visible.
  • ElevenLabs Conversational AI (the voice). This isn't plain text-to-speech; it's a real-time voice agent over a live connection. In my dashboard setup it runs on Claude Sonnet 4.6, handles microphone input and interruptions, and lets the app push silent background context updates that the agent can fold into memory without speaking every time.

Here's what a single tick looks like in the app's own pipeline log:

[10:20:26 PM] CAPTURE frame 1920x1144 -> 960x572 for vision
[10:20:29 PM] VISION  conf=1.00 age=Dark res(f:200 w:200 g:100 s:200) pop=4/5 vills=3 idleVills=3 mil=0 enemy=no | "The game has just started, and three villagers are currently idle near the Town Center. The scout is positioned nearby, and cows are visible for early food gathering."
[10:20:29 PM] CONTEXT (preview) GAME_STATE t=0:04 age=Dark vills=3 idleVills=3 pop=4/5 housed=true res(f:200 w:200 g:100 s:200) mil=0 enemy=unknown obs="The game has just started, and three villagers are currently idle near the Town Center. The scout is positioned nearby, and cows are visible for early food gathering."

If you look closely at that log, housed=true fired at 4/5 pop four seconds into the game. Early heuristic thresholds still have rough edges.

Making it feel like a coach instead of a chatbot

Most voice AI demos assume turn-taking: you ask a question, the agent answers, repeat. During a ranked match I almost never want to talk to my coach. My hands and brain are busy.

So the loop works in reverse. Every five seconds, the app compares the new vision reading to the previous one, feeds a silent GAME_STATE update into the conversation, and only sends an active nudge when a rule trips: idle villagers, getting housed, reaching a new Age, spotting the enemy.

ElevenLabs handles the parts of real-time voice I really didn't want to build from scratch: turn detection, letting me interrupt mid-sentence, and believable speech synthesis. What it doesn't solve for you is restraint. An unrestrained voice agent narrates everything, which gets unbearable within two minutes. I added a verbosity setting (phase in the UI) plus explicit rules in the system prompt so it stays quiet unless something actually matters and avoids repeating the same callout back-to-back.

Standing up the voice agent took an afternoon

I expected the voice agent to be the hardest engineering in the project. It ended up being an afternoon in the ElevenLabs dashboard:

  • System prompt: sets the persona, defines the build order I'm practicing (in the screenshot below, a 21-pop Ethiopian Fast Archers rush aiming for Feudal near 9:40), and explains which incoming messages are silent context versus nudges to speak.
  • Knowledge base: AoE2 build orders, civilization bonuses, and unit counters.
  • Guardrails, LLM, and voice: picked Claude Sonnet 4.6 for the conversation brain, enabled interruptibility, and chose an energetic sports-style voice (Ninja).
  • Real-time API: connected the Tauri app to the agent.
Screenshot: configuring TrebuCoach in the ElevenLabs dashboard, showing the Fast Archers system prompt, first message, Ninja voice, and Claude Sonnet 4.6 as the agent LLM
Screenshot: configuring TrebuCoach in the ElevenLabs dashboard, showing the Fast Archers system prompt, first message, Ninja voice, and Claude Sonnet 4.6 as the agent LLM

Almost all of my actual debugging time went into the vision side, not the voice.

Four decisions and trade-offs in the vision loop

1. Force nulls instead of guesses

A screenshot taken mid-fight or while panning across the map doesn't always give a clean view of every number. Left to itself, a vision model will guess a plausible resource count, and a confident hallucination ("you're floating 800 gold" when you have 100) kills your trust in the coach on the spot.

So the schema allows missing fields, and the prompt tells the model to return nothing rather than invent a value. When a field comes back missing, the app carries forward the last good reading instead of letting it drop to zero. The trade-off is obvious: if several frames fail to parse in a row, the coach silently works off stale state until a clean reading arrives.

2. Three separate toggles so I could debug vision for free

Early on, testing vision prompts while connected to ElevenLabs meant burning live voice minutes just to see if the HUD parser worked. Instead of one big "Start" button, I split the pipeline into three independent switches: Capture application, Vision extraction, and ElevenLabs agent.

With the first two on and the agent off, the pipeline log streams every captured frame, the parsed vision reading, and the exact GAME_STATE context payload that would have been sent to ElevenLabs, tagged preview. I could play an entire match and tune the vision prompt without spending a second of voice time. That single UI choice did more for quality than any prompt tweak.

Screenshot: TrebuCoach capture panel and match settings, showing the 1920x1144 Age of Empires 2 window alongside civ, build order, verbosity, 5000ms tick interval, and 0.5 vision scale Screenshot: the three-toggle pipeline in preview mode (capture on, vision on, agent off), logging the downscaled capture, vision extraction, and preview GAME_STATE context payload

3. Downscale every frame by 0.5x

Sending full 1920x1144 frames every five seconds adds up fast over a 30-minute game. Scaling each frame by 0.5 down to 960x572 cuts the pixel count by 4x while keeping the top HUD bar legible enough in practice for the model to read resources, population, and age.

I haven't run a controlled accuracy benchmark comparing full-res against half-res across full matches, so I can't claim zero accuracy loss. Some of the occasional number misreads may well be the cost of that downscale.

4. Poll every five seconds

A 5-second tick keeps latency and API spend reasonable for continuous play, and it's plenty fast for macro habits like idle villagers or floating resources. The cost is tactical blindness: five seconds is an eternity during a fight, so TrebuCoach can't help you micro archers or dodge mangonel shots.

Does it actually work?

Mostly, yes, and playing with it has been way more fun than I expected.

Right out of the gate it keeps me honest on the build order I configured. When I hit a new Age, it nudges me on how to rebalance my economy and what to do with the units I just unlocked. Once my scout finds the enemy base, it reacts to what shows up on screen and suggests counters. Where it helps me most is the exact phase where I usually fall apart: that messy mid-game moment where your plan breaks down and you need someone to tell you how to pivot.

Video: a live match with TrebuCoach coaching out loud, calling out idle villagers, an Age-up, and the enemy's strategy, plus getting tripped up by the classic Age of Empires 2 quirk that 🦏 = 🐗

When I do want to ask something mid-match, I can just talk to the agent directly. A typical exchange looks like:

Chat transcript — me / TrebuCoachclick to expand
me
should I push now or boom?
TrebuCoach
You're up a town center and he's still in Feudal. Keep booming, add a third town center, and pressure with your scouts so he can't expand.

It's definitely a v1, and it still gets things flatly wrong. It misreads a HUD number from time to time, gets confused by classic AoE2 quirks like a rhino functioning as a boar in the clip above, or gives advice that misses what just happened off-camera. I'd rather be upfront about that than pretend I shipped a grandmaster in a box. Even with the misses, the floor is useful because the habits it reinforces are the unglamorous ones that actually win games at my level.

Where this approach breaks down

Stating the boundary plainly makes the whole project easier to judge: TrebuCoach only knows what a careful human could read off your current viewport, five seconds at a time, and nothing more.

  • Off-screen state is invisible. If your camera is on your farms while your army walks into a castle, or you haven't looked at the enemy base in two minutes, the model has no idea.
  • No real build-order state machine yet. Even though the vision model reads the in-game clock (t=0:04) and I can bake a target build order into the ElevenLabs system prompt (like the 21-pop Ethiopian Fast Archers prompt above), nothing tracks step-by-step progress across arbitrary builds or reliably catches that you're ninety seconds late on step 7.
  • Heuristic glitches and misreads. Small HUD fonts still get misread occasionally, and simple state flags like housed=true at 4/5 pop in the log above need tightening.
  • No in-game overlay. Right now the Tauri window lives beside the game instead of rendering on top of it.

Wrapping up

My flight-stick weekend was about AI collapsing the ramp-up cost of an unfamiliar stack. This project felt different. A few years ago, building an app that watches a live game, parses what's happening, and coaches you in a natural voice would have been a multi-person research effort. Today all three pieces (vision, real-time voice, native desktop shell) are off-the-shelf, and the real work is glue code, keeping the vision readings honest, and figuring out when the coach should shut up.

What surprised me most is how different it feels from opening a chat tab. We mostly treat AI as a box you stop what you're doing to go type into. Having an agent sit beside you, watch the same screen, and only speak up when you missed two idle villagers feels much closer to playing with a friend in voice chat.

The plane flew. Now the coach talks. I have no idea what the next game I get obsessed with will be, but I'll probably end up building something faintly ridiculous to play it better.


The project is called Eleven AoE, and my code lives on GitHub. I skipped a few implementation details here for readability, and plenty of rough edges are still in progress.

A few things I want to build next:

  1. Proper build-order step tracking against the in-game clock, so TrebuCoach can tell you when you're falling behind any build order, not just a hardcoded prompt.
  2. An on-screen overlay, so coaching notes sit on top of the game instead of in a separate window.
  3. More voices and personalities: a calm coach for ladder anxiety, and a much less calm one for when I'm throwing a winning game.