Building Ada (part three): fixing the lag
This is part three of the series. Part one covers the hardware and how Ada became three small servers. Part two gave her speech to text with whisper.cpp, the time and the weather, and a voice from macOS's say.
Part two ended with "part three is music". It isn't. I gave Ada a better voice, and that made her slower. Fixing that took the rest of this post, and by the end Ada was pretending to be Home Assistant.
A better voice
Samantha, the macOS voice from part two, sounds like a computer. I wanted something more natural that still ran on my Mac, so I rendered the same weather sentence with three engines and listened to them side by side:
- macOS's
say, with Samantha - Piper, the engine Home Assistant uses
- Kokoro, an 82-million-parameter open model
Piper's samples came back as empty files. I'd hidden its error output, so I didn't notice until I tried to play them. Its macOS package looks for its pronunciation data at a folder path from the machine it was built on. A separate environment, an older release and its Python API all failed the same way, so I dropped it.
Kokoro's af_bella won. It's much better than Samantha. I'll probably move to a voice API eventually, but this is the first version of Ada that doesn't sound like a robot.
Kokoro runs in Python, and Ada has no runtime dependencies. So Ada starts one long-lived Python process and sends it a sentence at a time as a line of JSON. It sends back each sentence's audio, prefixed with its length. The model loads once. uv installs Kokoro the first time from the script's own header:
# /// script
# requires-python = "==3.12.*"
# dependencies = ["kokoro-onnx==0.6.1"]
# ///The lag
Kokoro is slower than say. The full weather reply takes about 2.2 seconds to make on my Mac's CPU. So Ada splits the reply into sentences and sends each one as soon as it's ready. On the Mac, the first sentence went out after about one second.
The Show still waited 2.2 seconds. I'd measured when Ada sent the first sentence, not when anyone heard it. In the mode Ada uses, TECHO5 collects the whole reply before it plays any of it.
So the better voice was slower than Samantha, who took about a second. TECHO5 has a setting called Reply delivery with a Streamed option. It only applies when Home Assistant is answering, though, not to the mode where the Show calls Ada's three servers.
Fillers through the side door
People say "um" or "let me check" while they think. If Ada couldn't answer faster, she could at least fill the gap. My first idea was a long joke about reading every article in the British Museum.
The Show only plays a reply after the chat server has answered, so a filler can't play during the wait. But TECHO5 has a way for one Show to make another talk: POST /announce on port 8181. It needs a house word set on the setup page. Each announcement carries an HMAC signature keyed from that word, so the word never crosses the network. Ada's first signed announcement played on the first try.
That gave Ada a trick for slow answers. She replies at once with a filler line. That ends the Show's turn, and the filler plays. When the real answer is ready, she sends it as an announcement.
On the first test the answer cut the filler off halfway. Ada voices her fillers when she starts, so she knows how long each one lasts. Now she holds the answer until the filler has finished, plus half a second. A long test filler played to the end, then the answer followed.
It still wasn't right. An announcement plays a chime first and shows up on the screen as an announcement.
Follow-ups, and asking first
If a reply ends with a question mark, the Show listens again without the wake word. TECHO5 also sends the last few messages of the conversation with each request. So Ada's weather now ends with "Do you want tomorrow's forecast?", and she reads her own last reply to work out what "yes" means. It worked on the Show the first time.
I wanted Ada to ask first, too: speak a question, then listen for the answer. TECHO5 only does that for Home Assistant. It's an announcement with start_conversation turned on.
Three things I wanted now needed Home Assistant: streamed replies, asking first, and later, knowing which Show you're talking to once there are two. So Ada would pretend to be Home Assistant.
Pretending to be Home Assistant
Home Assistant talks to the Show over the ESPHome API. That's a TCP connection on port 6053 that Home Assistant opens, so the direction flips again from part one. In direct mode the Show calls Ada. As Home Assistant, Ada calls the Show and keeps the connection open.
I split it into steps, with a checkpoint. If the first step wasn't working by the end of its first session, I'd stop and go back to Spotify.
Step one: the handshake
TECHO5 only accepts encrypted connections. ESPHome uses the Noise protocol, Noise_NNpsk0_25519_ChaChaPoly_SHA256, with the device's key as a pre-shared key. Node's crypto module has every piece it needs: X25519, ChaCha20-Poly1305 and SHA-256.
Before letting the Show judge it, I checked it against the Python library Home Assistant uses. I gave both sides the same fixed keys and recorded the Python library's bytes. Ada's handshake has to produce exactly those bytes:
const handshake = new Handshake(psk, undefined, fixedKeyPair(0x11));
assert.equal(handshake.writeMessage().toString("hex"), vector.msg1);
const { send, receive } = handshake.readMessage(Buffer.from(vector.msg2, "hex"));
assert.equal(send.encrypt(Buffer.from("hello ada")).toString("hex"), vector.adaToShow);The Show's key was in the backups folder of the laptop I'd flashed it from. The Show accepted the handshake first time:
handshake done with "echo-show-5" (3ce441b7c899)
hello: API 1.15, "echo-show-5 (go-esphome-device)", name "echo-show-5"
device: TECHO5 Echo Show 5 2nd gen (cronos), "echo-show-5", ESPHome 2026.5.1ESPHome's messages are protobuf. Ada needs about twenty of them, so instead of adding a dependency I wrote an encoder and decoder in about 90 lines. I checked each field number against Home Assistant's message definitions.
Step two: listening
Next, Ada connected in the same order Home Assistant does and subscribed to the voice assistant. The Show sent over 400 messages describing its buttons, settings and sensors, as it would to Home Assistant.
I switched the Show's Answered by setting to Home Assistant and asked for the weather. Ada saved 1.9 seconds of audio, and whisper read it back as "What's the weather?". The Show then sat thinking, because nobody told it what happened next.
Step three: answering
Home Assistant reports a voice request as a series of events, and TECHO5 acts on each one:
| Event | What it carries |
|---|---|
STT_END | What you said |
INTENT_END | Whether to listen again afterwards |
TTS_START | The reply's text |
TTS_STREAM_START, audio, TTS_STREAM_END | The reply's voice, 16 kHz mono |
RUN_END | The end of the request |
The audio can go too fast. The Show keeps 64 chunks waiting and drops anything after that, and Home Assistant sends 32 milliseconds at a time. So Ada keeps no more than a second ahead of what the Show has played.
The Show now plays each sentence as it arrives. The time came back very quickly. I haven't timed it on the Show itself yet.
The 15-second "yes"
The follow-up broke. I said "yes" and the Show kept listening. Both "yes" recordings were exactly 15.0 seconds, which is the Show's limit.
TECHO5 decides for itself when you've stopped talking after a wake word. On a follow-up, it waits for Home Assistant to say so. Ada never did.
In part one I deleted the end-of-speech detector I'd written, because the Show handles that itself. It came back. The first version used fixed loudness levels. In my room the background was 150 to 200, and the "yes" peaked at 2,600. Replaying the two real recordings through it, both ended at 1.9 seconds instead of 15.
The next test listened for 15 seconds again. Something was running in the room, and the background was about 400. My cut-off for quiet was a fixed 400, so the room never counted as quiet.
Now Ada judges loudness against the room's own level, measured during the request. That level drops straight away to any quieter moment and rises slowly. A unit test found the next problem. A steady talker slowly raised the room's level until their own speech counted as quiet, so it can't rise while someone is talking:
const floor = (this.#floor =
this.#floor === undefined
? Math.min(level, this.#s.firstFloorMax)
: level < this.#floor || this.#speaking
? Math.min(level, this.#floor) // speech never raises it, or a long sentence would end itself
: this.#floor + (level - this.#floor) * this.#s.floorRise);A request also ends 10 seconds after speech starts, whatever the room is doing. All three real recordings end at 1.9 seconds.
Step four: asking first
To ask first, Ada voices the question and serves it as a WAV file from the Mac. Then she sends the Show Home Assistant's announcement with start_conversation on. The Show fetches the file, plays it and listens. A POST /ask triggers it, and Ada only accepts that from the Mac itself.
curl -d "Do you want today's weather?" localhost:8001/askThe Show asked, I said "yes" without the wake word, and it gave me the weather.
Fillers, done properly
Ada sends the reply audio herself now, so a filler doesn't need the side door. If an answer takes longer than 1.5 seconds, Ada starts the reply stream with a filler from memory. The answer follows in the same stream once it's ready.
The long test filler played to the end, then the weather followed with no chime. The screen showed only the answer's words. The Show only learns the text when the answer is ready, so the filler never appears.
In practice nothing is slow enough to need one yet. Hearing, transcribing and answering all happen within a second, so you only hear a filler if something stalls. They're ready for when Ada has a language model that takes a few seconds to think.
What's next
Ada serves both routes, and the Show's Answered by setting picks one. The Home Assistant route is the one I use now.
Part four is music, for real this time. TECHO5 already lets the Show act as a Spotify Connect speaker. Ada needs to understand "play some Fleetwood Mac", search Spotify, and tell it to play on the Show.