AI/ML · Voice AI · 3 min read

Real-Time Voice Roleplay with AI Patients

Learners practise hospital conversations out loud with AI patients, relatives and doctors, each with their own voice.

At Eklan, I architected and shipped real-time voice roleplay for nurses and clinicians preparing to work in English-speaking hospitals: they talk out loud with AI characters while browser audio streams straight to the Gemini Live API.

My role
I designed and built the voice system end to end: token-locked streaming to the Gemini Live API, the browser audio engine, voice-activity tuning, phase pacing, the multi-character director, the guards against model failure modes and the test harness that measured every change.
Context
Founding AI Engineer, Eklan
Period
Sep 2026 – present
Status
Eklan · Founding AI Engineer
Platform
Web app with real-time browser audio

Eklan · Founding AI Engineer

  • 1 per agentlive session for each character in a scene
  • Built and load-testedthe multi-agent voice mode
  • 19automated checks in the voice test harness
  • TypeScript
  • Gemini Live API
  • Web Audio / AudioWorklet
  • WebSockets
  • Next.js
  • ElevenLabs

Roles: AI/ML Engineer · Software Engineer.

The problem

Eklan trains nurses and clinicians, many of them Korean-speaking, to communicate in English before they start work in English-speaking hospitals. Reading a dialogue is easy; answering a worried relative out loud, in real time, is the part that needs practice. The first version of the voice roleplay sent every turn through a server relay. It was slow, every scene had one voice, and the model decided for itself when a scene moved on.

Who it was for

Learners practise a scene that a tutor prepared for their class: a patient with a chart, a relative with questions, a doctor giving instructions. Tutors author and publish the scenes; learners join from the browser and talk.

My role

I designed and built the voice system end to end as the founding AI engineer: the token-locked streaming, the audio engine, voice-activity tuning, phase pacing, the multi-character director, the guards and the test harness. The screens themselves were designed by a teammate, and I merged that work onto this engine.

What I built

  • Direct streaming with locked tokens

    The browser talks to the Gemini Live API itself. The server only hands out short-lived tokens that fix the model, the instructions, the voice, transcription, session resumption and context compression, so the browser can't change any of them.

  • A browser audio engine

    AudioWorklet capture and playback, a noise gate, a turn tracker, interruption handling and resumable sessions, built for hospital wards rather than quiet offices.

  • Multi-character scenes

    A patient, a relative and a doctor can share one scene. Each extra character runs as its own live session with its own voice, and a fast Gemini Flash director decides who the learner is talking to.

  • The app keeps time

    Each scene phase has fixed minutes. The model can ask to move on, but the app only accepts that near the end of a phase, steers the scene as time runs down, and closes the phase itself when time is up.

  • Guards for model failure modes

    A floor guard holds back turns nobody asked for, a speaker guard cuts audio when the model speaks as the wrong character and asks again, speech markers are stripped, and an English-only check keeps the practice in English.

  • Tutor authoring

    One OpenAI GPT tool call turns a tutor's class notes and prep deck into a draft scenario. Tutors edit it, and publishing renders the narration and greeting with ElevenLabs in parallel and stores them on Cloudinary.

In an ensemble scene, characters also speak up on their own at set points in a phase, but only in natural gaps in the conversation, with no two voices overlapping in the final checks.

How it works

The learner’s browser captures audio and streams it straight to Gemini Live, using a short-lived token that the server has locked. When a scene has several characters, a fast director model picks who answers each turn. Guards decide what is allowed to play, and the app, not the model, keeps the scene’s clock.

The learner's browser captures audio and streams it straight to Gemini Live with a short-lived token the server locks; a fast director picks which character answers, guards filter what plays, and the app, not the model, keeps time. Relationships: Browser audio to Token route; Token route to Gemini Live sessions; Gemini Live sessions to Director; Director to Guards; Guards to Browser audio (audio that passes plays back); Phase clock to Gemini Live sessions (phase changes); Gemini Live sessions to Session record (transcript).

A voice agent can’t be checked by reading its code, so I also built an automated harness that uses the same session setup and the same audio engine as the browser. A synthetic student speaks with text-to-speech audio, 19 checks cover voice, turn-taking, phase timing, response time and overlap, and an LLM judge reads the transcript. Every prompt or engine change was measured with it before release.

Decisions that mattered

  • I chose streaming straight from the browser to Gemini Live with locked, short-lived tokens over relaying every audio chunk through our own server because the relay added a hop to every turn and a server to keep alive, while a locked token keeps the model, instructions and voice under server control without carrying the audio

  • I chose the app owns the scene clock over letting the model decide when a phase is over because in testing the model asked to move on far too early, so its phase-change calls became requests the app accepts only near the end of a phase

  • I chose one live session per character, plus a fast director model over one session that voices everyone because a single session drifts between voices and personas; separate sessions keep each character's voice and role stable, and the director only has to answer one small question per turn

Hard problems I solved

  • ProblemSome characters spoke in the wrong voice, and nothing in the logs said why.

    FixThe Live API silently accepted voice names it didn't know and fell back to a default voice. I wrote a check that rendered all 30 candidate voices and compared their pitch with the character each was meant for, found 8 that didn't read consistently, and limited every cast to voices that passed three runs out of three.

  • ProblemIn loud wards the model kept waiting for silence that never came.

    FixI tuned voice-activity detection, added a noise gate in the audio worklet, and gave learners a hold-to-talk mode and an "I'm done" control for the noisiest rooms.

  • ProblemThe model sometimes spoke when it wasn't its turn, or answered as another character.

    FixThe floor guard holds back unprompted turns, and the speaker guard cuts the audio and re-asks the right character when the voice and the speaker don't match.

Tech stack

Browser
Models and speech
  • Gemini Live API: Bidirectional audio, function calls and transcription
  • Gemini Flash: The director that routes each learner turn
  • OpenAI GPT: Drafting a scenario from a tutor's notes
  • ElevenLabs: Narration and greetings
Server and data

Outcome

The system streams voice straight from the browser, keeps its own scene clock, and routes each learner turn to the right character. The multi-character mode was built and load-tested, and the test harness measured every prompt or engine change before release. No usage figures are given here.

What the voice system does
PartResult
StreamingDirect from the browser to Gemini Live with locked tokens
Turn handlingVoice-activity tuning, a noise gate and interruption handling
Multi-character scenesOne live session per character, routed by a director model
TestingA 19-check harness with synthetic speech and an LLM judge

What I learned

With a live voice model, the model is one component. Timing, turn-taking and who gets to speak belong to the application.

The biggest gains came from taking decisions away from the model: who keeps time, who may speak, which voice belongs to which character. The other lesson was about rolling back. Two reliability commits for the multi-character mode made it less stable in testing, so I went back to the last stable version the same day and kept the commits recoverable instead of patching forward.

What I’d do next

Run the same harness checks against a sample of real sessions, so quality is tracked on real conversations as well as in testing.