Skip to content

feat(tools): add TextToSFX tool for text-to-sound-effect generation - #1268

Merged
edenreich merged 4 commits into
mainfrom
fix/issue-1227
Sep 22, 2026
Merged

edenreich merged 4 commits into
mainfrom
fix/issue-1227

Conversation

@inference-gateway-maintainer

@inference-gateway-maintainer inference-gateway-maintainer Bot commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Resolves #1227

Summary

Adds a TextToSFX tool that turns a text prompt into a short sound-effect or ambience clip (whoosh, click, riser, room tone) through the gateway's SFX API (POST /v1/audio/sfx, SDK CreateSFX), mirroring how TextToSpeech produces speech and TextToMusic composes music. The tool is gated by text_to_sfx.enabled (default false, hidden when false) and always requests WAV so the desktop video-editing skill can drop the clip on an audio lane.

Note on the integration test: the tokenless mock gateway (v0.6.1) does not serve /v1/audio/sfx, so TestTextToSFXToolAgainstMockGateway pins the current real behavior (one-line error naming the model, run completes, no partial file) - same approach as the merged TextToMusic test. The gap is filed against inference-gateway/tokenless#62.

Changes

  • internal/agent/domain: new SoundEffectService port next to SpeechService/MusicService (Generate(ctx, prompt, outPath, seconds *float32, loop *bool) error).
  • internal/agent/infrastructure/sfx_service.go: gateway implementation following speech_service.go - provider/model split via strings.Cut, sdk.Client.CreateSFX with response_format: wav, empty-payload guard, writes the file; errors name the configured model.
  • config: top-level text_to_sfx: block (enabled, model default elevenlabs/eleven_text_to_sound_v2, output_dir default ~/.infer/tmp/sfx, tri-state require_approval), provider/model validation when enabled, IsApprovalRequired("TextToSFX") case, and NeedsGatewayAudio() extended so enabling SFX auto-starts the gateway with AUDIO_ENABLED=true.
  • internal/agent/tools/text_to_sfx.go: tool with prompt (required), seconds (0.5-30, optional), loop (optional bool), output_path (bare name; the shared resolveMediaOutputPath helper hoisted by TextToMusic is reused, not copied). Result reports path, prompt, duration_seconds (via audio.WAVDurationSeconds) - the same shape TextToSpeech reports.
  • Wired through internal/agent/tools/registry.go (hidden unless text_to_sfx.enabled and the service is injected) and internal/container/container.go; counterfeiter line added to mocks:generate (FakeSoundEffectService).
  • Prompt/tool description defaults in config/prompts.go; INFER_TEXT_TO_SFX_* overrides come free from the reflective env loader.
  • Docs: docs/tools-reference.md, docs/configuration-reference.md and docs/directory-structure.md list the tool and its knobs.

Testing

  • Unit tests: internal/agent/tools/text_to_sfx_test.go (argument validation incl. seconds range, result shape, no-partial-file on failure, registry gating) and internal/agent/infrastructure/sfx_service_test.go (request shape via sdkmocks.FakeClient, default model, error handling).
  • Integration test tests/integration/text_to_sfx_test.go runs the tool against the mock gateway.

Follow-ups

Adds a TextToSFX tool behind text_to_sfx.enabled that turns a text prompt into a short sound-effect or ambience clip through the gateway's SFX API (POST /v1/audio/sfx), the way TextToSpeech produces speech. The domain gains a SoundEffectService port next to SpeechService/MusicService; the gateway implementation calls sdk.Client.CreateSFX and writes the WAV into text_to_sfx.output_dir (default ~/.infer/tmp/sfx). Config mirrors text_to_music: enabled, model (default elevenlabs/eleven_text_to_sound_v2), output_dir and tri-state require_approval; the shared media output_path rule already hoisted by TextToMusic is reused. Enabling the tool also adds to the gateway's AUDIO_ENABLED requirement alongside speech and music.
@edenreich
edenreich marked this pull request as ready for review September 22, 2026 18:42
@edenreich
edenreich requested a review from a team as a code owner September 22, 2026 18:42
Unit tests mirror the text_to_speech and text_to_music patterns: argument validation (seconds 0.5-30, loop bool, bare output_path), result shape (path, prompt, duration_seconds via audio.WAVDurationSeconds), no partial file on provider failure and registry gating. The infrastructure test exercises sdk.Client.CreateSFX through sdkmocks.FakeClient (request shape, default model, error paths). One integration test pins the mock-gateway behavior, which does not serve /v1/audio/sfx yet. Docs: tools-reference, configuration-reference and directory-structure list the tool and its text_to_sfx knobs.
tokenless 0.8.0 serves POST /v1/audio/sfx and /v1/audio/music with canned
clips, so the TextToSFX and TextToMusic integration tests move from pinning
the missing endpoint to the happy path, and new e2e tests drive both tools
headless plus the SFX tool through the chat TUI in tmux.
ElevenLabs produces no WAV for sound effects (only mp3, pcm, opus, ulaw,
alaw), so the gateway rejected every real TextToSFX call. The tool now
asks for mp3, writes sfx-*.mp3, and its prompt and docs say so; the
duration_seconds result field goes with the WAV reader. Verified against
a live ElevenLabs key. Spec cleanup tracked in inference-gateway/schemas#219,
mock parity in inference-gateway/tokenless#65.
@edenreich
edenreich merged commit 3f80ebe into main Sep 22, 2026
1 check passed
@edenreich
edenreich deleted the fix/issue-1227 branch September 22, 2026 19:39
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.206.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Sep 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE] TextToSFX tool for text-to-sound-effect generation

1 participant