Srijan Guchhait

A voice loop for a coding agent

Speaking to a coding agent from a desktop orb or a phone: speech-to-text, a text-to-speech fallback chain, and keeping the brain on one machine.

  • voice
  • agents
  • tauri
  • bun

I wanted to give my coding agent a task out loud, hear the answer and check on its work from my phone. I built a small bridge between a floating desktop orb or a phone app and the agent on my laptop. Three decisions shaped it.

Keep the brain in one place

The agent, its session runtime and its tools run only on my Linux laptop. A phone cannot run them. So the laptop is the only part that touches the agent. Every other part is a thin client that knows a server address and a secret.

The flow has five steps.

  1. A client records speech or takes typed text. It is a Tauri 2 app on desktop and Android. It sends the input to the server over HTTP.
  2. The server converts audio to a 16 kHz mono WAV with ffmpeg. Then whisper.cpp transcribes it with a small English model.
  3. The server sends the transcript to the lead agent session as a message.
  4. The agent replies through a command on the laptop. The server broadcasts events to every connected client over a WebSocket. The events are accepted, transcript, sent, reply, audio chunks and an end marker.
  5. A text-to-speech engine speaks the reply. The audio chunks stream to the client as they are produced.

The same client code runs on Linux, Windows, macOS and Android. The continuous integration builds all of them and runs the server tests on the three desktop systems.

Three small interfaces

The server is Bun and TypeScript with no runtime dependencies. Speech-to-text, text-to-speech and the agent connection each sit behind a small interface. Each one takes a few lines to replace.

  • Speech-to-text is whisper.cpp or any external command that takes a WAV path and prints a transcript.
  • Text-to-speech is a shared warm daemon, the worker of the server itself, or nothing.
  • The brain is the real agent or an echo backend that returns what it receives.

The echo backend turned out to be the most useful one. It lets me test the whole loop on a machine without an agent and without paying for a model call. This includes the transcription, the reply events and the audio. Most of my bugs lived in the plumbing and not in the model.

A fallback chain for speech

Speech output fails more often than the rest, because it needs a model process that stays loaded in memory. I solved it with a chain.

  1. The server first asks a warm speech daemon that already holds the voice model. That avoids loading a second copy.
  2. If the daemon does not answer, the server logs one line and uses its own worker. That worker runs the same voice model in a long-lived process.
  3. If audio is off, the server sends text only.

The reply text is never lost. A failure in the speech path costs the spoken part and keeps the written part. The server also keeps the last 100 non-audio events. A client that reconnects after a bad network patch asks for everything since the last event it saw.

Treat the network as hostile

A server that passes text to an agent that edits files is dangerous when left open. The defaults reflect that.

  • The server listens on the loopback interface until I change it.
  • Every route except the health check needs a bearer token. The WebSocket takes the token as a query parameter, because browsers cannot set headers on a WebSocket.
  • The installer writes a random token into a file with restricted permissions. It never changes the firewall.
  • The documentation says not to expose the server to the internet. To reach it from my phone, I put the laptop on a private overlay network and bind the server to that address only.

I also recorded a failure I hit. My phone reported "no route to host" while the laptop was fine. A firewall rule dropped inbound traffic on the overlay interface. The fix is to allow one port on one interface. Opening more would be wrong.

Small details

  • The orb starts recording on one tap and sends on the next. Global shortcuts do not reach Wayland apps on some desktops. There, a custom shortcut calls the toggle command of the app, and a single-instance plugin hands it to the running copy.
  • The client can send text or audio and print its logs from the command line. That is how I test it in CI without a microphone.
  • Every connection attempt, status code and network type goes into a buffer inside the app, with the token hidden. When something fails on the phone, I read the reason without a cable.

What I would do again

I keep the expensive and fragile part on one machine and make every other part a replaceable client. I put each outside dependency behind an interface small enough to fake. Every failure ends as text. I also wrote the security defaults for a tired version of me who skips the documentation.

← All posts