Repository navigation
feat(tts): add opt-in TextToSpeech tool with local Qwen3-TTS synthesis - #1118
Conversation
Mirror the speech-to-text architecture: a text_to_speech config section (disabled by default, env-overridable via INFER_TEXT_TO_SPEECH_*), an audio.Synthesizer that shells out to a local llama.cpp llama-tts binary running Qwen3-TTS GGUF models (stock voice, or zero-shot voice cloning from a reference WAV normalized via ffmpeg), and a TextToSpeech agent tool registered only when enabled so the tool definition never reaches the LLM payload otherwise.
…ults; add docs docs/text-to-speech.md mirrors speech-to-text.md (prerequisites, config, models, troubleshooting), tools-reference gains a TextToSpeech entry, cspell gains gguf/mmproj. Tests: synthesizer with a fake command runner (stock + cloned voice arg assertions, binary/model missing errors, WAV duration parsing), tool validation/execution/formatting with a fake synthesizer, registry gating (tool absent from the payload when disabled), config defaults, and INFER_TEXT_TO_SPEECH_* env overrides.
…ed in path expression' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…ed in path expression' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…ed in path expression' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…ed in path expression' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…ed in path expression' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…ed in path expression' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
…ed in path expression' Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
|
@infer Can you address all the failing issues in the CI? also review any other places - the code produced by you initially was not secure and Github Action bot suggested many fixes. use /ponytail:ponytail /go /go-concurrency If the skill instructions or the AGENTS.md needs to be updated with the new adjusted rules then please document these. |
|
Model: Todos
Pull Request✅ Infer Result: SuccessAll CI checks are green. Let me close out the todo list: All CI checks are green. Final summary: CI fixed - all checks passCodeQL, lint, build, build-macos, e2e, postgres, test, and vet all pass on commit Root causes and fixesCodeQL (2 high,
lint - Security review of the rest of the new code
DocumentationAs requested, the adjusted rule is now documented in AGENTS.md - Security Gotchas: LLM-supplied tool paths must be reduced with Model: Tokens: 5,406,823 in · 39,129 out · 5,445,952 total (51 requests) Tool calls: 75 total · 100% success rate TracesStatsTriggered by edenreich · Infer Action · OSS |
…boundary CodeQL's go/path-injection taint tracks through custom guards (sandbox checks, filepath.Clean/Rel containment), so the previous autofixes never silenced the two high alerts. Both LLM-supplied paths are now reduced to a bare file name via filepath.Base (the query's documented sanitizer) and joined onto a trusted directory: voice_sample resolves inside the working directory, output_path inside the configured output dir. Absolute paths, separators and .. stay rejected with actionable errors, the sample is symlink-resolved and re-validated before opening, and WAVDurationSeconds bounds the fmt-chunk allocation. Also flattens Validate into resolveSamplePath/resolveOutputPath helpers (fixes the nestif lint failure), drops the synthesizer's redundant out-dir containment that rejected the default ~/.infer/tts flow, and documents the pattern in AGENTS.md Security Gotchas.
|
@infer Can you address this comment? #1115 (comment) |
|
Model: Todos
Pull Request✅ Infer Result: SuccessAll done - branch is clean and everything is pushed. Here's the summary. Addressed: m13v's review on #1115 - "the acceptance criteria catch a missing model but not a half-downloaded one"The finding: What changed (commit
|
Downloads are now byte-count verified against the server Content-Length before being cached, and existing cached model files (tts and whisper) are size-checked via a HEAD probe before reuse, so a half-downloaded or manually truncated model is re-fetched instead of failing synthesis on every run. Unknown sizes (offline probe, missing Content-Length) keep trusting the cache, and auto_download: false models are never re-fetched behind the user's back. Addresses review feedback on issue #1115.
The telemetry decorator overrode only ExecuteTool and embedded the rest of the interface, so user-typed !! invocations went through ExecuteToolDirect uninstrumented: a session whose only activity was a direct tool call produced a root span with no children and no execute_tool duration metric. Both entry points now delegate to a shared record() so the instrumentation cannot drift apart again, and direct runs carry infer.tool.direct=true to distinguish them from the model's own calls in a trace tree.
Qwen3-TTS pulls ~1.4GB of GGUFs on first use and whisper models are not much smaller, but the status line sat on a motionless "Executing..." for the whole transfer with no sign anything was happening. Adds a ToolProgressCallback context port, mirroring the existing BashOutputCallback, and reports through it from downloadToFile - so whisper models and the prebuilt ffmpeg/binary fetch are covered too, not just TTS. Reporting is throttled to once a second, and the reader is left unwrapped when no callback is present, so headless runs pay nothing. Also surfaces the underlying error text when a direct execution fails: both the !! tool and bash paths previously reported a bare "Execution failed" and threw the reason away.
Qwen3-TTS needs a build that knows the qwen3tts architecture and accepts -mm/--mmproj for llama-tts. Older packaged builds satisfy neither and fail with "unknown model architecture: 'qwen3tts'" or "invalid argument: -mm", neither of which the troubleshooting section mentioned.
Co-authored-by: Eden Reich <[email protected]>
Co-authored-by: Eden Reich <[email protected]>
- resolveSamplePath: drop the EvalSymlinks re-check. It fed a fully-resolved path into ValidatePathInSandbox, which resolves its own sandbox dirs with filepath.Abs; on macOS /tmp and /var are symlinks to /private/..., so every voice sample under them was rejected and the package tests failed on darwin. The ValidatePathInSandbox call above it is what every other file tool uses. - tests: require.NoError/require.True before dereferencing result, so a failed assertion reports instead of segfaulting the rest of the package. - resolveBinary: remove the llama-tts auto-download branch. The stt-binaries release hosts only ffmpeg and whisper-cli, so it could never succeed and only delayed the "not found" error by a wasted round-trip. - progress: publish ticks through a new non-blocking publishToolProgress. publishToolStatusChange keeps its blocking send - dropping a terminal failed/completed event would leave a tool showing as "running" forever. - cachedModelStale: bound the HEAD probe at 5s. It runs before every transcription and synthesis on a client with no timeout of its own, and a timeout lands on the existing "trust the cache" branch. - config: honour text_to_speech.require_approval so the tool's approval policy can be overridden, matching the image tools. - docs: cover the feature in README (features bullet plus a Media tools table that also picks up the previously undocumented image tools), and note that llama-tts is never auto-downloaded and prebuilt ffmpeg is Linux-only.
resolveViperEnvironmentVariables walked struct fields by reflection and its reflect.Pointer case only recursed into non-nil struct pointers, so every pointer-to-scalar field was skipped outright. That silenced all 23 *bool options - every tool's require_approval, plus auto_install and cleanup. docs/configuration-reference.md has documented INFER_TOOLS_WRITE_REQUIRE_APPROVAL, INFER_TOOLS_EDIT_REQUIRE_APPROVAL, INFER_TOOLS_DELETE_REQUIRE_APPROVAL and INFER_TOOLS_BASH_REQUIRE_APPROVAL all along; setting any of them did nothing. The docs described the intent, the resolver never implemented it. - setPointerOption allocates the pointer when the key is set, so an unset option stays nil and IsApprovalRequired keeps falling through to the global tools.safety.require_approval default. Unset stays distinct from explicit false. - The five duplicated scalar cases collapse into setScalarFromViper, shared with the pointer path so the two cannot drift. - Tests cover the precedence chain in memory (defaults -> config file -> env, env wins) and pin that a load with no override leaves the shipped non-nil defaults for Write, Edit, Delete and Agent untouched. Also documents INFER_TEXT_TO_SPEECH_REQUIRE_APPROVAL and notes that approval variables are tri-state.
|
🎉 This PR is included in version 0.184.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Resolves #1115
Summary
Adds speech synthesis as a sibling of the existing speech-to-text feature, in two modes: text to speech (text in, WAV out, stock voice) and voice to voice (text in plus a short reference WAV, spoken in the cloned voice). Exposed as an opt-in agent tool - when
text_to_speech.enabledis false (the default) the tool is not registered and its definition never reaches the tools payload sent to the LLM, so it costs zero prompt tokens.The engine chosen for the first iteration is Qwen3-TTS via llama.cpp's
llama-tts(one of the issue's candidates and now llama.cpp's flagship TTS demo): a standalone local binary, GGUF models in the same ecosystem as whisper.cpp, and--tts-speaker-filefor zero-shot voice cloning. No CGO is added to theinferbinary - everything shells out, mirroringinternal/audio's existing approach, with model auto-download into~/.infer/models/ttsand ffmpeg-based reference-sample normalization reusing the package's converter building blocks and prebuilt-ffmpeg download from stt-binaries.Changes
config/config.go: newTextToSpeechConfigsection (enabled,engine,model,auto_download,output_dir,binary_path,models_dir,timeout,ffmpeg_path) withResolveOutputDir(default~/.infer/tts), engine validation inConfig.Validate(qwen3-ttsonly for now), defaults, and anIsApprovalRequiredcase. All fields are env-overridable via the existing viper layer (INFER_TEXT_TO_SPEECH_*).config/prompts.go: defaultTextToSpeechtool description (overridable via prompts.yaml).internal/audio/synthesizer.go:SynthesizerwithSynthesize(ctx, text, voiceSamplePath, outPath)- resolves the binary (explicit path, PATH,~/.infer/bin), ensures models, normalizes the voice sample to 16kHz mono WAV capped at 30s via ffmpeg (with a too-short guard), and invokesllama-tts -m <backbone> -mm <mmproj> -p <text> [--tts-speaker-file <sample>] -o <out>. Missing binary/ffmpeg/model yield actionable install errors. Also exportsWAVDurationSecondsso callers can report audio duration without external tools.internal/audio/ttsmodel.go:TTSModelManagerdownloading the backbone and mmproj GGUFs (default presetQwen3-TTS-12Hz-1.7B-Base-Q4_K_M+ itsQ8_0mmproj;q8/bf16presets or explicit<backbone>[,<mmproj>].gguffilenames) fromggml-org/Qwen3-TTS-12Hz-1.7B-Base-GGUFinto~/.infer/models/tts, temp-file + rename, honoringauto_download: falsefor manually placed models.internal/agent/tools/text_to_speech.go:TextToSpeechtool following theImageGenerationToolshape -textrequired, optionalvoice_sample(sandbox-validated, must exist and be readable) andoutput_path(write-validated);IsEnabledrequires the feature flag and a supported engine; result reports the WAV path, duration, and whether the voice was cloned.internal/agent/tools/registry.go: registers the tool only whentext_to_speech.enabledis true, on top of the per-toolIsEnabledgate.docs/text-to-speech.md: setup, config, model table, cloning guidance, troubleshooting (mirrorsdocs/speech-to-text.md); plus a tools-reference entry and cspell words.INFER_TEXT_TO_SPEECH_*env overrides.Acceptance criteria notes
cfg.TextToSpeech.Enabled;GetToolDefinitionsfilters byIsEnabled()), pinned byTestTextToSpeechTool_RegistryGating.~/.infer/models/tts(ormodels_dir);auto_download: falsewith a manually placed model works. Binary auto-download applies "where applicable": llama-tts is looked up on PATH or viabinary_path(the STT binary release does not ship a llama-tts asset yet; the resolver will pick one up automatically if it is added), while ffmpeg is auto-downloaded into~/.infer/binas a last resort.docs/text-to-speech.md+docs/tools-reference.md); surfacing the feature in the org docs site is tracked in [DOCS] Document the TextToSpeech agent tool (text-to-speech and voice cloning) docs#592.