Skip to content

About

Give any LLM agent a cloned voice: its reply in, one spoken line out, via an OmniVoice TTS server.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

 
 

Repository files navigation

agent-voice

Give any LLM agent a cloned voice. The agent's reply goes in; one in-character spoken line comes out of your speakers in a voice cloned from a 3–10 second clip.

my-agent --reply | agent-voice pipe --voice skippy
[writer/omnivoice] Parser is fixed and all forty-one tests pass, Rico. You can stop hovering now.

The tag in front is [<how the line was chosen>/<engine that spoke it>].

  • Two channels. The screen keeps the full technical reply. The speaker gets one line — either the agent tags it (<say>...</say>) or a small "writer" model reads the reply and decides what the character would say.
  • Any agent, any language. A CLI, a stdin pipe, and a tiny HTTP server (POST /say). Nothing to import unless you want to.
  • Optional ElevenLabs. Give a voice an ElevenLabs voice ID and a key, and ElevenLabs speaks it, falling back to OmniVoice if the call fails.
  • Any OmniVoice server. Speaks the /health + /synthesize contract used by scorbo2/ai-playground and TalkWithMe. If you already run one, it works unchanged.
  • Small. Python 3.11+, one dependency (httpx), standard-library HTTP server, ~650 lines, 27 tests, mypy strict.

It grew out of a Claude Code session that wanted to talk as Skippy without a browser in the loop.

Quick start

git clone https://github.com/rodaddy/agent-voice.git
cd agent-voice
sh install.sh --demo          # venv, install, demo voice (macOS), then a report

Then edit agent-voice.env (it's created for you) so AGENT_VOICE_TTS_URL points at your OmniVoice server, and:

.venv/bin/agent-voice doctor                          # everything green?
.venv/bin/agent-voice speak --voice demo "It works."  # hear it

doctor names every missing piece and the fix for it. The full walkthrough — including standing up the OmniVoice server, making a real voice, and picking a writer model — is in INSTALL.md.

The three doors

You have... Use Example
A string agent-voice speak agent-voice speak --voice skippy "Build is green."
An agent's reply on stdout agent-voice pipe my-agent | agent-voice pipe --voice skippy
Anything that can POST JSON agent-voice serve curl localhost:7161/say -d '{"text":"...","voice":"skippy"}'

How the spoken line is chosen

pipe and POST /say take a whole reply and pick what to say (--mode auto):

  1. <say> tag. If the agent wrote <say>One spoken line.</say>, exactly that is spoken. Tags quoted inside code spans are ignored, so an agent can talk about the tag safely. Tell your agent: "End every reply with one spoken line wrapped as <say>...</say>: one or two short sentences, in character, plain words only."
  2. Writer model. Otherwise, if AGENT_VOICE_LLM_URL is set, the reply is sent to that OpenAI-compatible model together with the voice's persona.md, and the model answers with one or two sentences in character (capped at AGENT_VOICE_MAX_WORDS, never cut mid-sentence). A small local model is plenty — a 9B on a laptop writes the line in ~2.5 s.
  3. Direct. Otherwise the text itself is spoken, markup stripped.

--mode tag|writer|direct forces one of them. Utterances are serialized inside one process, so agents sharing one agent-voice serve (or one Python Speaker) take turns. Separate agent-voice pipe processes do not share that lock and can talk over each other.

Voices

A voice is a directory. Make as many as you like.

voices/skippy/
  ref.wav        3-10 s of the voice, mono, 24 kHz  (longer is slower and no better)
  ref.txt        the exact words spoken in ref.wav
  language.txt   optional, default "English"
  persona.md     optional: who this voice IS -- the writer model speaks as this
  elevenlabs.txt optional: an ElevenLabs voice ID (see below)

ElevenLabs (optional)

A voice can be spoken by ElevenLabs instead of your OmniVoice server. Both are needed:

  1. A voice ID in a non-empty voices/<name>/elevenlabs.txt (just the ID; surrounding whitespace is ignored; an empty file means OmniVoice). In ElevenLabs, add the voice to My Voices, then use Copy voice ID from its menu.
  2. An API key in AGENT_VOICE_ELEVENLABS_API_KEY. A key with text-to-speech access is enough.
Variable Default Meaning
AGENT_VOICE_ELEVENLABS_API_KEY (unset) ElevenLabs API key; unset or empty = OmniVoice only
AGENT_VOICE_ELEVENLABS_MODEL eleven_flash_v2_5 any ElevenLabs TTS model_id
AGENT_VOICE_SPEED 1.0 overall speaking rate, 0.5–2.0. ElevenLabs renders up to its own 0.7–1.2 range and playback speeds up the rest (afplay -r, ffplay atempo; pitch kept). OmniVoice is sped up at playback only. A voice folder can pin its own rate with speed.txt. At 1.0 no voice settings are sent.

How it behaves:

  • Which engine. ElevenLabs speaks when the key is set and the voice has a non-empty elevenlabs.txt. Every other voice, and every voice when no key is set, goes to OmniVoice as before. You can mix both in one library.
  • Request. POST https://api.elevenlabs.io/v1/text-to-speech/<voice id> with output_format=pcm_24000; the raw 24 kHz mono 16-bit PCM that comes back is wrapped in a WAV header, so playback and out/ work the same for both engines. Timeout 30 s.
  • Fallback. If the call fails (any HTTP error status such as a bad key, unknown voice or exhausted quota, a timeout, or no network), agent-voice prints elevenlabs failed: <reason>; using OmniVoice to stderr. The reason is the first 200 characters of ElevenLabs' error response for an HTTP error, or the exception text for a timeout or network failure. It then speaks the line with the voice's ref.wav through OmniVoice. The line is never lost to an ElevenLabs outage, which is why a voice still needs ref.wav and ref.txt: without them it is not a voice at all. If OmniVoice is down too, the error is raised as usual.
  • Seeing which engine spoke. pipe prints [tag/elevenlabs] ... or [tag/omnivoice] ...; POST /say returns it in the engine field, and the Python API in Spoken.engine. speak prints only the WAV path. A run of omnivoice with no elevenlabs failed line means no key reached the process or the voice has no (or an empty) elevenlabs.txt. doctor does not check ElevenLabs.
  • Keys. At the time of writing, ElevenLabs keys are 51 characters (sk_ + 48), and a truncated paste is rejected with invalid_api_key_length. Check a key's length, never print it. Keep the key in your environment or a secrets manager rather than in agent-voice.env, and never commit it.
  • Cost. Only the chosen line is sent. A <say> line is capped at 300 characters and is usually about 100. Direct mode (agent-voice speak, --mode direct, or pipe//say on a reply with no <say> tag and no writer) sends up to 600 characters, so it is the expensive path. Flash v2.5 is one of ElevenLabs' low-cost models; check your plan's per-character price and usage page.
  • serve has no authentication. With a key set, anyone who can reach POST /say spends your ElevenLabs quota. Keep AGENT_VOICE_HOST on 127.0.0.1, or put the server behind something that authenticates.
  • Voices you may use. Use premade, Voice Library or your own designed voices. Do not clone a real person's voice without their consent; that breaks ElevenLabs' terms.

Making a voice

examples/make-voice-macos.sh voices/demo builds a throwaway voice from the macOS say command. examples/persona-ship-ai.md is a starting persona. Cutting a real clip from a recording is in INSTALL.md.

HTTP server

agent-voice serve                       # http://127.0.0.1:7161
curl -s localhost:7161/health
curl -s localhost:7161/say -H 'content-type: application/json' \
  -d '{"text": "Deployed.\n<say>It is live. Try not to break it.</say>", "voice": "skippy"}'
{"spoken": "It is live. Try not to break it.", "wav": "out/skippy-20260828T025959Z.wav", "voice": "skippy", "source": "tag", "engine": "omnivoice"}

POST /say takes text, optional voice, optional mode; answers 204 when there was nothing to say, 404 for an unknown voice, 502 if the TTS or writer failed.

Python

from agent_voice import Config, Speaker

speaker = Speaker(Config.from_env())
spoken = speaker.speak(agent_reply, "skippy")   # Spoken(text, wav, voice, source, engine) or None

With playback enabled, spoken.wav is deleted after successful playback. Set AGENT_VOICE_PLAY=false or use --no-play to keep the WAV.

Configuration

Environment variables, or the same names in agent-voice.env in the working directory (the environment wins). agent-voice doctor shows what is in effect.

Variable Default Meaning
AGENT_VOICE_TTS_URL http://127.0.0.1:8181 OmniVoice server (scorbo2's runs on 8181)
AGENT_VOICE_VOICES_DIR voices the voice library
AGENT_VOICE_VOICE first voice default voice name
AGENT_VOICE_LLM_URL (unset) OpenAI-compatible base URL of the writer; unset = no writer
AGENT_VOICE_LLM_MODEL writer model id
AGENT_VOICE_LLM_API_KEY sent as Authorization: Bearer if set
AGENT_VOICE_ELEVENLABS_API_KEY (unset) ElevenLabs key; unset = OmniVoice only (ElevenLabs). Set it in the environment, not in agent-voice.env
AGENT_VOICE_ELEVENLABS_MODEL eleven_flash_v2_5 ElevenLabs model
AGENT_VOICE_SPEED 1.0 overall speaking rate (0.5–2.0)
AGENT_VOICE_NUM_STEPS 10 OmniVoice diffusion steps (10–20 on scorbo2's server)
AGENT_VOICE_GUIDANCE_SCALE 1.2
AGENT_VOICE_MAX_WORDS 35 cap on a writer-produced line
AGENT_VOICE_OUT_DIR out where WAVs are written before playback or saved with --no-play
AGENT_VOICE_PLAY true play then delete the WAV; false to save without playing
AGENT_VOICE_HOST / _PORT 127.0.0.1 / 7161 for agent-voice serve

Integrations

  • Claude Code — two hooks and a toggle make a Claude Code session speak each reply (where this tool came from).
  • Anything else needs only a way to run agent-voice pipe with the reply on stdin, or to POST the reply to /say. Shell agents, LangChain callbacks, cron jobs, CI notifications — all the same three lines.

Commands

agent-voice speak  [--voice NAME] TEXT           say exactly this
agent-voice pipe   [--voice NAME] [--mode M]     reply on stdin -> spoken line
agent-voice serve                                HTTP: POST /say, GET /health
agent-voice voices                               list the library
agent-voice health                               TTS + library as JSON
agent-voice doctor                               what's missing, and the fix

--no-play before the subcommand saves the WAV without playing it.

Development

sh install.sh --dev
.venv/bin/pytest && .venv/bin/ruff check && .venv/bin/ruff format --check && .venv/bin/mypy

See CONTRIBUTING.md. MIT licensed.

About

Give any LLM agent a cloned voice: its reply in, one spoken line out, via an OmniVoice TTS server.

Resources

Contributing

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

⌂ Proxy