Skip to main content
Glama
voice-agent-mcp

voice-agent-mcp

by evious
README.md
# voice-agent

Local voice dictation and read-aloud for AI coding agents.

One core, exposed twice: a **CLI** and an **MCP server**. Thin skills tell
Claude Code, Cursor and GitHub Copilot when to call them.

- **Local by default**: whisper.cpp for dictation, system voices for speech.
- **No cloud**: Edge TTS exists as an explicit opt-in engine, never a default.
- **No Electron, no editor plugin**: a small Node package plus process adapters.

## Status

Early development. Speech and dictation work on Windows and Linux; the MCP
server is next.

| Milestone | Scope | State |
| --- | --- | --- |
| M0 | Scaffold, core primitives, CI | done |
| M1 | `speak` / `stop` / `voices` / `doctor` / `config` | done |
| M2 | `dictate` with whisper.cpp, models, clipboard | done |
| M3 | Windows capture (DirectShow) parity | done |
| M4 | MCP server (`dictate`, `speak`, `stop`, `doctor`) | done |
| M4.1 | Configurable dictation model | done |
| M5 | piper neural voice (offline) | done |
| M6 | `menu` + config tools in MCP | done |
| M7 | VS Code extension (status bar) | built, needs field validation |
| M8 | Automatic piper install on first use | done |
| M9 | `setup` + skills for Claude Code, Cursor, Copilot | next |
| M10 | VS Code Marketplace | planned |

## VS Code extension

`vscode/` builds a small extension with two status-bar buttons:

- **$(mic) Dictar** — start recording; click again to stop and transcribe.
  No silence detection: you decide when it ends, which is the only thing that
  works in a noisy room.
- **$(unmute) Leer** — read the last Copilot answer (falls back to the
  selection) with piper.

Dictated text goes where `voiceAgent.insert` says: `chat` (default), `editor`
or `clipboard`. In `chat` mode it focuses the chat input and pastes, so it
does not overwrite what you already typed.

```bash
cd vscode
npm install
npm run package        # -> voice-agent-0.1.0.vsix
```

Then install the `.vsix` from the Extensions view (⋯ → Install from VSIX) or
with `code --install-extension voice-agent-0.1.0.vsix`.

## Quick start

```bash
npx -y @evious/voice-agent doctor            # what is installed and missing
npx -y @evious/voice-agent speak --text "Hola, esto es una prueba."
npx -y @evious/voice-agent dictate           # press Enter to stop, or wait for silence
npx -y @evious/voice-agent stop              # interrupt playback, from any terminal
```

The first `speak` downloads piper and a voice for your language (~90 MB, once);
the first `dictate` downloads whisper.cpp and its model (~65 MB, once). Both are
checksum-verified and resumable. `--no-download` (or
`VOICE_AGENT_NO_DOWNLOAD=1`) turns that off.

Install it globally to drop the `npx`:

```bash
npm i -g @evious/voice-agent
voice-agent menu        # language, engine, voice, model, rate
```

Read a file or a pipe:

```bash
voice-agent speak --file respuesta.md
cat respuesta.md | voice-agent speak --stdin
```

## Commands

| Command | What it does |
| --- | --- |
| `speak --text/--file/--stdin` | Clean the Markdown and read it aloud |
| `dictate` | Record, transcribe with whisper.cpp, optionally copy |
| `stop` | Kill the active playback (works across processes) |
| `voices [--language es]` | List installed voices, default marked with `*` |
| `voices install [id]` | Download piper and a neural voice |
| `menu` | Interactive settings: language, engine, voice, model, rate, tests |
| `models [list\|download [id]]` | Manage the whisper.cpp binary and models |
| `doctor [--fix] [--json]` | Check tools, paths, models and config |
| `config get` / `set` / `path` | Inspect or change voice, rate, language, `skipCode` |

Useful flags: `--voice <id>`, `--rate 0.5..2`, `--engine system`,
`--model base-q5_1`, `--max-seconds 60`, `--copy`, `--no-download`,
`--no-skip-code`, `--wait`, `--json`.

## MCP server

`voice-agent-mcp` speaks Model Context Protocol over stdio. stdout belongs to
the protocol, so every log line goes to stderr.

| Tool | What it does |
| --- | --- |
| `voice_dictate` | Record, transcribe, optionally copy. Blocks until silence or `maxSeconds` (default 15). |
| `voice_speak` | Start read-aloud and return immediately, so the agent can keep working. |
| `voice_stop` | Stop the active playback. Idempotent. |
| `voice_doctor` | Report engines, voices, models and paths. |
| `voice_config_get` / `voice_config_set` | Read or change language, engine, voice, model, rate. |
| `voice_install` | Download a piper voice or a dictation model (verified, resumable). |

Every tool answers with JSON in a text block. `voice_dictate` returns
`empty: true` when nothing was heard: that is an answer, not a tool error, so
the agent can ask the user to repeat instead of breaking the turn.

VS Code / Copilot (`.vscode/mcp.json`):

```json
{
  "servers": {
    "voice-agent": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "--package", "@evious/voice-agent", "voice-agent-mcp"]
    }
  }
}
```

From a local checkout, point at the built entry instead:
`"args": ["/absolute/path/to/voice-agent/dist/mcp.js"]` with `"command": "node"`.

Claude Code:

```bash
claude mcp add voice -- npx -y --package @evious/voice-agent voice-agent-mcp
```

The MCP server must run on the machine with the microphone. Under WSL that is
WSLg; on Windows it is DirectShow.

## Requirements

- Node.js 22 or newer.
- Linux: `ffmpeg` and `espeak-ng` (both in `apt`).
- Windows 11: `ffmpeg` on `PATH`; PowerShell and SAPI voices ship with Windows.

`voice-agent doctor` reports exactly what is missing and, on Debian/Ubuntu,
`doctor --fix` offers to install it after asking.

## Design notes

- Every subprocess runs through `core/exec.ts` with `shell: false` and an
  argument array. User profiles contain spaces, paths contain backslashes and
  Spanish text contains non-ASCII characters; arrays avoid all quoting bugs.
- Playback is detached and tracked through a pidfile, so `stop` works from a
  different process and from a future MCP call. Only one utterance plays at a
  time: a new one replaces the previous one.
- **Windows**: the player is spawned with `DETACHED_PROCESS`. Without it the
  child shares the parent console and dies the moment `speak` exits, which
  makes `stop` impossible. Found the hard way.
- **Dictation**: whisper.cpp is pinned to a release and every download is
  verified against a sha256 from the Hugging Face index. Transfers resume from
  `<file>.part`, so a dropped connection does not restart 57 MB.
- **Endpointing**: `silencedetect` ends the utterance, but only after speech
  was detected once. A leading silence must not cut the user off before they
  start talking.
- **Windows capture** uses the DirectShow *alternative name*
  (`@device_cm_...\wave_...`), not the friendly name: on a Spanish Windows the
  friendly name is localized and parsing it is a bug waiting to happen.
- **piper** is pinned to the last MIT release with standalone binaries
  (2023.11.14). The maintained fork is GPL-3 and ships Python wheels only.
  That release rejects phoneme maps with multi-codepoint entries, which every
  current Spanish voice has (English diphthongs such as `aɪ`), so the voice
  config is sanitized before use: those keys are dropped, everything else is
  kept. Without that patch piper aborts with "Phonemes must be one codepoint".
- **`engine: auto`** means "piper if installed, otherwise the system voice",
  so installing a voice is all it takes to upgrade read-aloud.
- **First run installs the good voice.** `speak` with `engine: auto` downloads
  piper and the preferred catalog voice for the resolved language (es/en),
  because falling back to espeak was the single worst first impression. It
  announces the download and respects `--no-download` / `VOICE_AGENT_NO_DOWNLOAD`.
- **Recording has two modes**: silence endpointing (for the MCP tool, where
  nobody can press a button) and push-to-talk (`silenceMs: 0`, used by the
  extension). Endpointing assumes speech when the microphone never reported
  silence, otherwise a recording that starts mid-sentence was cut at 5 s.
- `VOICE_AGENT_INPUT=<file.wav>` feeds a file instead of the microphone (in
  real time) and `VOICE_AGENT_PLAYER` replaces the audio player. Both exist for
  tests and headless machines.
- **Windows**: PowerShell scripts are written as UTF-8 **with BOM** and force
  `[Console]::OutputEncoding = UTF8`. Without that, PowerShell 5.1 reads
  accents as ANSI and returns stdout as CP850 (`ñ` becomes `0xA4`).
- **Windows** has no `LANG`, so the UI culture is queried from PowerShell to
  pick the default voice. Otherwise Spanish text is read by an English voice.
- Paths follow platform conventions (`XDG_*`, `%APPDATA%`, `%LOCALAPPDATA%`).
  `VOICE_AGENT_HOME` overrides everything, which the tests use as a sandbox.
- Temporary WAVs are deleted on stop and swept after one minute, never while
  they are still playing. Nothing is logged: no text, no audio.

## Development

```bash
npm run typecheck
npm run test
npm run build
node scripts/smoke-mcp.mjs        # real MCP session, needs a downloaded model
```

CI runs the same steps on Ubuntu and Windows with Node 22 and 24.

`.vscode/mcp.json` is gitignored because it points at your machine; copy
`.vscode/mcp.json.example` if you want the workspace server.

## License

MIT