Repository navigation
Studio: add an Audio API card to Settings and open it from Audio pages - #12821
Conversation
A script with an API key can now do what the Audio pages do, against /v1:
- /v1/audio/speech takes a saved voice (id or {"id"}), a built-in speaker
of the model, or a reference clip to clone, and returns wav, mp3, flac,
opus, aac or pcm. History keeps the WAV.
- /v1/audio/transcriptions gives OpenAI segments and words on audio.cpp
models, plus diarized_json for models that tell speakers apart.
- /v1/audio/run takes a model and loads it, refusing one that cannot run
the workflow before the resident model is evicted. API runs show in the
API monitor.
- Audio inputs, saved voices and history clip files answer on /v1, with
the upload streamed past the /v1 body cap. URLs returned on /v1 point
at /v1.
- A timed /v1/audio/transcriptions upload past 30 minutes is refused with 413, like the plain one, instead of being transcribed cut short. - pcm speech is 24 kHz mono, the format OpenAI's clients play. - The input sweep reaps a prepared upload a crash left behind.
A timed transcription can wait an hour on the aligner download before audio.cpp reads its copy, so the sweep reaps a leftover copy after the inputs' 24 h TTL, not the hour a temp file gets.
Settings → API keys only showed chat examples. The new Audio API card shows copy-ready curl, Python and JavaScript calls for Speak, Clone, Transcribe and the /v1/audio/run workflows (Separate, Convert, Music, Edit), filled in with this server's URL, the revealed key and a downloaded model that can run each one. - Which model clones, converts, edits or makes music comes from the Audio pages' audio.cpp catalog, since /v1/models lists only a task. - Transcribe asks for segment timestamps only on models that return them, and the Edit body is built by the same adapter the Edit page uses for that model family. - The card says when no downloaded model fits, and when Model auto-switch is off, since a named model does not load then. - The Secure HTTPS switch moves up to the tab so both cards share it.
Each Audio page gets a "Use via API" button in its header, left of the Library link. It opens Settings → API keys at the Audio API card, on that page's workflow and with the page's model filled in. The model is used only when it can run the workflow, so a separator still loaded while Speak is open falls back to a downloaded speech model. The button shows its label only where the header has room beside the Create/Train pills, and is icon-only with a tooltip otherwise.
|
@codex review |
- Convert on RVC sends no target recording and picks a built-in voice instead, since RVC refuses a target. - Music on Stable Audio's SFX build and ControlFoley asks for a sound effect, since they make no songs. - An Audio page's model is used only when /v1/models lists it and it can run the workflow, so a resident chat model never ends up in a speech example. - The JavaScript workflow examples wait for runs longer than 5 minutes instead of failing on fetch's default response timeout. - With keyless access set to everything else, the examples use the keyless placeholder key, and the card no longer says a key is always needed. - Picking a language in the Audio card keeps the chat card's stored variant of that language (Python + tools stays).
|
@codex review |
|
Settings → API keys now has an Audio API card under Usage examples. It gives copy-ready curl, Python and JavaScript calls for Speak, Clone, Transcribe and the Separate, Convert, Music and Edit workflows, filled in with the server URL, the revealed key and a downloaded model that can run each one. Each Audio page's Use via API button opens the card on that page's workflow and model. What changed
Generated Speak, Transcribe, Clone and Separate calls ran against a Studio built from this branch and returned audio, timestamped segments and four stems. The fixed Convert and Music bodies return 200 from Before: merge base |
|
Breakdown of the red checks here (the run was created at 05:31 UTC):
|
unslothai#12812 landed on main as a squash, so its backend files take main's version. Keep the Use via API import and audioApiRequested beside main's imports and requestedTab rename.
…bout loading only once it answers
|
Review record for #12821, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#507. Findings are quoted as posted and attributed to the account that posted them. The reactions shown are the triage recorded on the mirror; none were re-applied here. Commits are named as the mirror's, with this PR's equivalent where one was found. Round 1: reviewed mirror
|
|
Review record for this PR, continued from the comment above (part 2 of 2). Round 3: reviewed mirror
|
Share the Secure HTTPS switch through tunnel-preference so the MCP section follows it too.
|
@codex review |
1 similar comment
|
@codex review |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6be7d63134
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ${uploads.map((item) => `${item.name} = upload(${j(item.file)})`).join("\n")}${uploads.length ? "\n" : ""}result = post("/v1/audio/run", json=${render(body, "python")}) | ||
|
|
||
| # ${save} | ||
| for clip in result["clips"]: |
There was a problem hiding this comment.
Save the inline audio fallback from workflow runs
When /v1/audio/run succeeds but cannot persist the generated clip (for example with a full or read-only gallery), _audio_run_response deliberately returns clips: [] and the WAV as audio.data (studio/backend/routes/inference.py:23365-23368). This loop—and the JavaScript, PowerShell, and bash branches below—only handles clips, so every copied workflow example exits without saving the successfully generated output exactly when that fallback is used; decode and write the inline audio payload when it is present.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing: the inline audio fallback only appears when _persist_tts_clip raises (a failed disk write on the server), so it is a degraded host state rather than a normal run, and the copy-ready examples stay focused on the normal clips path.
|
@codex review |
1 similar comment
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6be7d63134
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| loadOpenAIAutoSwitchSettings().then( | ||
| (settings) => !cancelled && setAutoSwitch(settings.enabled), | ||
| () => undefined, | ||
| ); |
There was a problem hiding this comment.
Handle owner-only auto-switch reads for managed users
For any managed non-owner, this call returns 403 because /openai-auto-switch is on _owner_settings_router (studio/backend/routes/settings.py:241,2314), yet AudioApiExamples mounts outside the owner guard (api-keys-tab.tsx:193-221). Its rejection is swallowed and leaves autoSwitch null, while needsLoad only warns for false; with default-off switching and only a downloaded/unloaded audio model, the card therefore offers a model-specific command the backend rejects as not loaded without the intended load warning. Read this global state through a route available to API users or treat this denial conservatively.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Not changing: this only affects managed non-owner accounts and only hides an advisory line; the generated request is the same and is correct whenever the owner has auto-switch on.
The OpenAI SDK sends fs.createReadStream as a chunked multipart body, which Studio refuses with 411 Content-Length required. toFile reads the clip so the request carries a length.
A model handed over while it was still downloading, or loaded and unloaded later, never reached the card, which read /v1/models once per mount. Relist on the chat examples' pace: 15 s until something is resident, 60 s after.
|
@codex review |
1 similar comment
|
@codex review |
|
Codex Review: Didn't find any major issues. 🚀 Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |

Summary
Settings → API keys only had chat examples, so nothing showed how to call the audio routes from #12812. A new Audio API card under Usage examples has copy-ready curl (bash or PowerShell), Python and JavaScript calls for Speak, Clone, Transcribe and the
/v1/audio/runworkflows (Separate, Convert, Music, Edit). Each call uses this server's URL, the revealed key and a downloaded model that can run it. Each Audio page also gets a "Use via API" button that opens the card on that page's workflow and model.Changes
/v1/modelslists audio models only astext-to-speechorautomatic-speech-recognition, so the card reads the Audio pages' audio.cpp catalog (and their family hints for repos it does not know) to find a model that can clone, convert, edit or make music. A loaded model comes first, then the Audio pages' default order.me.wavto/v1/audio/inputs, saves it with/v1/audio/voices, then speaks with the saved voice id. The workflow examples upload their inputs and download every clip the run returns. Python useshttpxand JavaScript usesfetchfor these Studio routes, since the OpenAI SDK has no method for them.verbose_jsonwith segment timestamps only on audio.cpp families that return them (Parakeet TDT, MOSS Transcribe Diarize, VibeVoice ASR, Kroko). Other models get plain text, since they answer a timestamp request with an error.EDIT_ADAPTERSbuilder the Edit page uses, so DotTTS, FireRedAudio and Vevo2 each get their own edit format.sk-unsloth-YOUR_KEY.UsageExamplesup toApiKeysTab, so both cards use the same base URL.HighlightedCodeis exported for reuse.apiAudioExamplein the settings panel prefs. The language and OS pills share the chat card's prefs.openAudioApi({ workflow, model })on the settings dialog store, which opens API keys and scrolls to the card. The page's model is used only when the catalog says it can run that workflow, so a separator left loaded while Speak is open falls back to a downloaded speech model. The label shows only when the header has room beside the Create/Train pills; otherwise the button is an icon with a tooltip.Testing
From
studio/frontend:npm test npm run typecheck npm run i18n:check npm run buildnpm test: 10589 of 10591 pass. The two failures (tests/color-themes.test.tsandtests/find-in-page.test.ts) are in files this PR does not touch; Frontend tests: read the composer shadow and palette seeds where #12800 left them #12810 fixes them on main.typecheck,i18n:checkandbuildpass.tests/audio-api-snippets.test.ts(routes, escaping, PowerShell vs bash curl, Edit body per family, timestamp gating, model picks) andtests/audio-api-request.test.ts(Use via API opens the card; the request is dropped on leaving the tab), plus additions totests/openai-model-catalog.test.tsandtests/settings-panel-prefs.test.ts.bash -n,py_compile,node --checkand the PowerShell parser.Before / after
Built from main (
c174a7db5) and from this branch after merging main (6be7d6313); the later commits only change the JavaScript transcription example and how often the card relists models, nothing in these frames.Audio page header: "Use via API" sits left of Library.
Settings > API, opened by that button: the new Audio API card with the Speak / Clone / Transcribe / Workflows tabs and a ready-to-run
/v1/audio/speechcall. Before, the tab has only the chat usage examples.