Repository navigation
feat(tools): add text-to-music generation tool - #1265
Merged
Merged
Conversation
Adds a TextToMusic tool composing music from a text prompt through the gateway's Music API (sdk Client.CreateMusic, response_format wav), mirroring TextToSpeech/TextToSFX shape: prompt/seconds/instrumental/output_path inputs, text_to_music.enabled gating (default false), MusicService domain port with gateway implementation, shared resolveMediaOutputPath helper, container/registry wiring, counterfeiter fake, unit and integration tests, and docs.
7 tasks
This was referenced Sep 22, 2026
inference-gateway-maintainer
Bot
marked this pull request as ready for review
September 22, 2026 16:59
inference-gateway-maintainer
Bot
requested a review
from a team
as a code owner
September 22, 2026 16:59
Fold validatePromptAndOptions back into Validate, pass the optional duration and instrumental pointers straight to the SDK request, drop the zero-value TextToMusic block from DefaultConfig, and share one fakeWav test helper between the media tool tests.
Covers enabling, env overrides, gateway requirements (AUDIO_ENABLED and provider credentials), tool usage and troubleshooting; linked from the README, the tools reference and the directory structure page.
…_music is on The Audio API flag was keyed only off gateway-engine text_to_speech, so enabling text_to_music alone started a gateway without /v1/audio/music and every tool call failed with a 404. Route the three checks through Config.NeedsGatewayAudio, which also covers music.
… for named files The gateway music providers do not serve wav (elevenlabs offers mp3, opus and pcm), so the hardcoded wav response format failed every call with a 400. Request mp3, write a .mp3, and drop the WAV-only duration readout. resolveMediaOutputPath only created the output directory on the timestamped branch, so a caller-named output_path failed with ENOENT on a fresh machine; create it for both branches (fixes TextToSpeech too).
Contributor
|
🎉 This PR is included in version 0.206.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Resolves #1261
Summary
Adds a
TextToMusictool that composes a music clip from a text prompt through the gateway's Music API (sdk.Client.CreateMusic,response_format: mp3), mirroring theTextToSpeech/TextToSFXshape:prompt, optionalseconds(maps toduration_seconds), optionalinstrumental, andoutput_path(bare file name). The tool is gated bytext_to_music.enabled(default false) and reportspathandprompt. Output is MP3: the gateway music providers do not serve wav (ElevenLabs offers mp3, opus and pcm), verified against the real provider. It builds on the SDK v1.38.0 bump from PR #1262 (CreateMusicwith per-endpointCreateMusicRequestResponseFormatMp3).Note on the mock gateway: the tokenless mock gateway does NOT serve
POST /v1/audio/music, so the integration test pins the real behavior of a gateway without the endpoint - the tool call fails with a one-line error naming the configured model (music generation with elevenlabs/music_v2_5 failed: ...), the agent run still completes, and no partial file is left behind. The gap is tracked as inference-gateway/tokenless#59.Note on the shared helper: the issue pointed at the
output_pathhelper from #1227 (TextToSFX), which has not landed yet, so this PR extractsresolveMediaOutputPathout ofTextToSpeechToolininternal/agent/tools/text_to_speech.go(behavior-preserving refactor plus theprefixparameter); #1227 can reuse it.Changes
MusicServiceport ininternal/agent/domain/media.go(error-onlyCompose(ctx, prompt, outPath, seconds, instrumental)signature) next to the speech port.internal/agent/infrastructure/music_service.goimplementingMusicServiceviasdk.Client.CreateMusicwithCreateMusicRequestResponseFormatMp3, writing the returned MP3 to the configured output dir.internal/agent/tools/text_to_music.go- definition, validation, execution and formatting; failures (provider error, gateway without the endpoint, invalidoutput_path) surface as one-line failed results and leave no partial file (timestamped targets are removed on failure, caller-named targets are left untouched).text_to_musicblock (enableddefault false,modeldefaultelevenlabs/music_v2_5,output_dirdefault~/.infer/tmp/music,require_approval) plus prompts entry;INFER_TEXT_TO_MUSIC_*env overrides come from the reflective env loader.tests/mocks/agentdomain/fake_music_service.goadded tomocks:generate.resolveMediaOutputPathextracted fromTextToSpeechToolsooutput_pathrejects directories, absolute paths and..through one function.tests/mocks/sdkFakeClient, config tests, and an integration test running the tool against the mock gateway.docs/text-to-music.mdpage mirroringtext-to-speech.md(enabling, env overrides, gateway requirements, tool usage, troubleshooting), linked from the README,docs/tools-reference.mdanddocs/directory-structure.md;docs/configuration-reference.mdupdated; a[DOCS]ticket is filed against inference-gateway/docs.Config.NeedsGatewayAudio()gatesAUDIO_ENABLED=true(and the audio-restart probe) on gateway-engine speech or music. Before this, enablingtext_to_musicalone started the local gateway without/v1/audio/musicand every call 404'd.Review follow-ups (later commits)
refactor(tools):Validatefolded back to the TextToSpeech shape (invalidoutput_pathis an argument error, like speech),seconds/instrumentalpointers passed straight to the SDK request, zero-valueTextToMusicblock dropped fromDefaultConfig, one sharedfakeWav()test helper.docs(tools): thedocs/text-to-music.mdpage above.fix(gateway): theAUDIO_ENABLEDgap above, with a "music only" row inTestNeedsAudioRestart.fix(tools): live test against ElevenLabs showed the hardcoded wav format fails every call with a 400, so the tool now requests MP3, writes.mp3and drops the WAV-only duration readout. The same test showedresolveMediaOutputPathonly created the output directory on the timestamped branch, so a caller-namedoutput_pathfailed with ENOENT on a fresh machine; it now creates it on both branches, which fixes TextToSpeech too.Follow-ups
POST /v1/audio/musicin the mock gateway so integration coverage can assert a successful clip.[DOCS]ticket mirroring this change on the docs website.TextToMusicin the video-editing skill and add amusiclane.