Repository navigation
Description
Summary
Add speech synthesis as a sibling of the existing speech-to-text feature (docs/speech-to-text.md, internal/audio/), in two modes:
- Text to speech (TTS): text in, spoken
.wavout, using a stock voice. - Voice to voice (voice cloning): text in plus a short reference recording (a ~10-30s
.wavof the target speaker), spoken.wavout in the cloned voice. This is the interesting mode for video-editing workflows, similar to what Voicebox demonstrated (Voicebox itself was never released, so we use an open zero-shot model).
Exposed as an optional agent tool, disabled by default: when disabled, the tool definition is NOT included in the tools payload sent to the LLM, exactly like every other config-gated tool in the registry.
Design
Mirror the speech-to-text architecture 1:1 - same config shape, same shell-out-to-a-local-binary approach (no CGO in the infer binary), same model auto-download and caching flow.
Config (config/config.go)
New TextToSpeechConfig section, modeled on SpeechToTextConfig:
text_to_speech:
enabled: false # feature flag (default: false) - tool is absent from the LLM payload when false
engine: "" # synthesis engine (see open questions)
model: "" # engine-specific model id (auto-downloaded like whisper GGML models)
auto_download: true # download the model on first use if missing
output_dir: "" # where generated wavs go; empty = ~/.infer/tts
binary_path: "" # explicit engine binary path; empty = resolve on PATH
models_dir: "" # model cache; empty = ~/.infer/models/tts
timeout: 300 # synthesis timeout (seconds)All fields overridable via env vars (INFER_TEXT_TO_SPEECH_ENABLED=true, ...), same as speech-to-text.
Synthesis backend (internal/audio/)
Extend the existing package rather than creating a new one:
synthesizer.go-SynthesizerwithSynthesize(ctx, text, voiceSamplePath, outPath) error;voiceSamplePath == ""means stock-voice TTS, non-empty means cloning. Shells out to the engine binary, reusing the package's existingcommandRunner/lookPathtest seams (exec.go) and binary resolution order (explicit path, PATH lookup,~/.infer/bindownload).- Reuse
ModelManager/BinaryManager(model.go,binary.go) for model/binary download and caching, parameterized for the TTS engine. - Reuse
convert.go(ffmpeg) to normalize the reference sample to whatever the engine expects (e.g. 16kHz/24kHz mono WAV) and to validate/trim it. - Missing binary or model produces an actionable install error naming what to install, never a silent failure (same contract as the transcriber).
Agent tool (internal/agent/tools/text_to_speech.go)
New TextToSpeech tool registered in internal/agent/tools/registry.go, following the ImageGenerationTool shape:
Definition()parameters:text(string, required) - what to say.voice_sample(string, optional) - path to a.wavof the target speaker; when set, the output clones that voice. Recommend ~10-30s of clean speech in the description.output_path(string, optional) - defaults to a timestamped file undertext_to_speech.output_dir.
Validate()- non-empty text; ifvoice_sampleis set, the file must exist and be readable (path validated against the sandbox rules like other file-taking tools).IsEnabled()- returnsconfig.TextToSpeech.Enabled(and a resolvable engine). Because the registry only includes enabled tools in the chat-completion tools payload, the tool costs zero prompt tokens for everyone who has not opted in.- Result: path to the generated
.wavplus duration, formatted for preview like other tools.
Engine (open question - decide before implementing)
Constraint: must run fully local and be callable as a standalone CLI binary, like whisper-cli. Candidates:
- Qwen3 TTS family / CosyVoice (mentioned in the original request) - strong zero-shot cloning; check availability of a prebuilt CLI or GGUF runtime rather than a Python stack.
- OuteTTS via llama.cpp's
ttsexample - GGUF, same ecosystem as whisper.cpp, supports speaker profiles from a reference sample. - piper - tiny and fast but stock voices only; would cover mode 1, not cloning.
Pick ONE engine for the first iteration (the config engine field leaves room for more later, no engine abstraction layer until a second engine actually lands).
Scope
- In scope: the config section, the synthesizer, the
TextToSpeechtool, docs (docs/text-to-speech.mdmirroringdocs/speech-to-text.md), unit tests with the existing fake-runner seams. - Out of scope (follow-ups if wanted): a
/saychat shortcut, replying with voice notes on Telegram, audio playback in the TUI, streaming synthesis.
Acceptance Criteria
-
text_to_speechconfig section exists, defaults toenabled: false, env-var overridable. - With the feature disabled (default), the
TextToSpeechtool definition is not present in the tools payload sent to the LLM. - With the feature enabled, the LLM can call
TextToSpeechwithtextonly and a.wavfile is produced with the stock voice. - With
voice_samplepointing to a ~10-30s reference.wav, the produced.wavspeaks the given text in the cloned voice. - Model and (where applicable) engine binary are auto-downloaded on first use and cached under
~/.infer/models/tts/~/.infer/bin;auto_download: falseplus a manually placed model also works. - Missing binary/ffmpeg/model yields an actionable error naming the missing piece and how to install it.
-
docs/text-to-speech.mddocuments setup, config, and troubleshooting, in the style ofdocs/speech-to-text.md. - Unit tests cover the synthesizer (fake command runner) and tool validation; no network or real audio needed in CI.
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsDone
Activity
[-][FEATURE] Implement text to voice and voice to voice[/-][+][FEATURE] Text to speech and voice to voice (voice cloning) as an opt-in agent tool[/+]edenreich commentedon Aug 28, 2026
@infer can you work on this? use /go /go-concurrency
inference-gateway-maintainer commentedon Aug 28, 2026
Model:
ollama_cloud/glm-5.3-flash· View JobTodos
Pull Request
#1118
✅ Infer Result: Success
All work is complete and verified. Here is the summary of what was done:
Summary
I implemented issue #1115: text-to-speech (TTS) and voice-to-voice (voice cloning) as an opt-in agent tool, in PR #1118 (#1118), now marked ready for review.
Engine decision (the issue's open question): I picked Qwen3-TTS via llama.cpp's
llama-tts- one of the issue's candidates and now llama.cpp's flagship TTS demo. I verified against the llama.cpp source thatllama-ttsis a standalone CLI (-m backbone.gguf -mm mmproj.gguf -p "text" -o out.wav) with--tts-speaker-filefor zero-shot cloning, and confirmed the real GGUF filenames inggml-org/Qwen3-TTS-12Hz-1.7B-Base-GGUF(backboneQwen3-TTS-12Hz-1.7B-Base-Q4_K_M.gguf+mmproj-...-Q8_0.gguf).Changes
config/config.go): newtext_to_speechsection mirroringspeech_to_text-enabled: falseby default, env-overridable (INFER_TEXT_TO_SPEECH_*) via the existing viper layer, engine validation (qwen3-ttsonly),ResolveOutputDir(default~/.infer/tts), defaults (timeout 300, auto_download true).internal/audio/synthesizer.go,ttsmodel.go): shells out tollama-tts(binary resolution: explicit path -> PATH ->~/.infer/bin), auto-downloads backbone + mmproj GGUFs into~/.infer/models/tts(presetsbase/q8/bf16or explicit filenames), normalizes the voice sample via ffmpeg (16kHz mono, capped at 30s, too-short guard), and reuses the package'scommandRunner/lookPathseams,BinaryManager(prebuilt ffmpeg fallback) andresolveFFmpeg. Missing binary/ffmpeg/model produce actionable install errors. Added stdlibWAVDurationSecondsso results report audio duration without external tools.internal/agent/tools/text_to_speech.go):TextToSpeechfollowing theImageGenerationToolshape -text(required),voice_sample(optional, sandbox-validated),output_path(optional, write-validated),IsEnabled()requires the feature flag + supported engine. Registered in the registry only when enabled, so a disabled feature costs zero prompt tokens (pinned by a registry gating test).docs/text-to-speech.mdmirroringdocs/speech-to-text.md(prerequisites, config, model table, cloning guidance, troubleshooting), plus a tools-reference entry and cspell words.golangci-lintpasses with 0 issues; pre-commit hook ran clean on both commits.Tracking
PR: #1118 -
Resolves #1115, marked ready for review.Model:
ollama_cloud/glm-5.3-flash· Exit Code:0· Duration: 23m 47sTokens: 23,118,382 in · 78,672 out · 23,197,054 total (127 requests)
Tool calls: 163 total · 100% success rate
Artifacts
README.md(2.0 KB)Download all artifacts
Traces
Stats
Triggered by edenreich · Infer Action · OSS
m13v commentedon Aug 28, 2026
the acceptance criteria catch a missing model but not a half-downloaded one. auto_download just checks the file exists, so an interrupted first fetch leaves a truncated model on disk, the exists check passes, and the next run skips re-download and hands the engine a corrupt file. that quietly turns a retryable network failure into a permanent one, and Validate() only asserts voice_sample exists, not that the model is intact. worth checksumming the cache so a bad download re-fetches instead of failing synthesis forever with the same file every run.
edenreich commentedon Aug 28, 2026
@m13v thanks for the heads up - I'll have a look.
fix(audio): re-fetch truncated cached models instead of trusting them
inference-gateway-releaser commentedon Aug 30, 2026
🎉 This issue has been resolved in version 0.184.0 🎉
The release is available on:
Your semantic-release bot 📦🚀