Skip to content

Studio: speak through a saved connection on the Audio page - #14288

Merged
danielhanchen merged 10 commits into
unslothai:mainfrom
NilayYadav:audio-speak-connections
Oct 22, 2026
Merged

danielhanchen merged 10 commits into
unslothai:mainfrom
NilayYadav:audio-speak-connections

Conversation

@NilayYadav

@NilayYadav NilayYadav commented Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator

Settings > Voice can read replies aloud through a saved connection, but the Audio page's Text to Speech tool only offered local models.

The Speak picker now has a Connected section. OpenAI connections offer gpt-4o-mini-tts, tts-1 and tts-1-hd, and self-hosted connections (Kokoro, vLLM, llama.cpp and others) offer the models they list. Picking one sends the text, voice (alloy when empty), style instructions and speed to the connection's /audio/speech with its saved key. The clip lands in Speak's history like a local one, and Stop cancels the call. The load device, saved voices and model options are hidden while a connection is picked.

Picking a local model or turning connections off goes back to local speech.

Part of #14194

Before / after

Studio built at the merge base (left) and at this branch (right), with a saved custom connection named Scene Speech Box pointing at a local OpenAI-compatible server that lists kokoro and whisper-large-v3.

Text to Speech picker: the Connected tab now appears and lists only the speech model, not the speech-to-text one.

Speak picker before and after

Speaking through the connection: the rail shows the Voice, Style instructions and Speed fields, one request goes to /v1/audio/speech with voice af_heart, and the clip plays and lands in History.

Speak through a connection before and after

@NilayYadav NilayYadav self-assigned this Oct 19, 2026
@danielhanchen

Copy link
Copy Markdown
Member

Frontend unit tests (Windows) fails on this PR, not on main:

not ok 703 - Audio exposes the shared picker eject action only while idle
  location: studio/frontend/tests/audio-model-eject.test.ts:13
  The input did not match the regular expression /onEject=\{\s*audioEjectAvailable\(\{ ...

That test pins the onEject={audioEjectAvailable({...}) ? handleEject : undefined} wiring in audio-page.tsx, and this PR changes it to onEject={!connection && audioEjectAvailable({...}) ? ...}. The behaviour change looks intended (no Eject while a saved connection is speaking), so the test needs to follow it: either allow the !connection && prefix in the regex, or move the connection check into audioEjectAvailable (it already takes the other gating inputs) and add a connection case to its unit test. The second keeps the policy in one tested place. The Linux frontend tests will hit the same assertion.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

1 similar comment
@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-20T17:23:31.545379Z 5c7807d Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 381246fc7a

ℹ️ 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".

Comment on lines +563 to +567
provider_id: request.providerId,
model: request.model,
voice: request.voice,
speed: request.speed,
...(request.instructions ? { instructions: request.instructions } : {}),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Forward retained browser-only keys for connection speech

When a connection has no server-saved key because legacy-key migration failed but its key remains in browser storage, this path sends only the provider/model/voice fields. The supported Read Aloud path in studio-speech-synthesis-adapter.ts handles exactly this state by encrypting getExternalProviderApiKey(...) and sending both provider_base_url and encrypted_api_key; AudioRunRequest exposes neither, so _external_tts_speech receives no credential and Audio-page generation fails upstream even though the same saved connection still works for Read Aloud. Carry the legacy credential snapshot through /audio/run (including backend request fields) or reuse that adapter logic.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this: a browser-only key exists only until the next provider sync moves it to the server, so this path does not reach a real session.

},
signal?: AbortSignal,
): Promise<AudioRunResponse> {
const response = await authFetch("/api/inference/audio/run", {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Revalidate the connection before retrying authentication

When the first POST gets a 401 or a Tauri network retry, authFetch can resend this body, but this call supplies no beforeRetry guard. If Connections is disabled or the same provider is edited while refresh/retry is pending, the backend can still send the prompt through the server-enabled row or its changed URL; generateCustomTtsAudio captures the row and installs assertConnectionSnapshot before every retry specifically to prevent this. Apply the same connection-policy and snapshot check here.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this: it needs the connection to be disabled or edited inside a single auth refresh window; the next request uses the current row.

if (busyRef.current === null) setSpeakConnectionId(id);
return;
}
if (modeRef.current === "speak") setSpeakConnectionId(null);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Preserve the connection when a busy local pick is ignored

While connection speech is generating, the model picker remains interactive, so choosing a local row executes this clear and then calls handleModelSelect; that function immediately returns when busyRef.current !== null (use-audio-model-slot.ts:917-920). The requested local model is therefore neither queued nor loaded, while the active connection disappears and the UI falls back to the previous local selection after generation. Gate this clear with the same busy check or clear only after the local selection is accepted.

Useful? React with 👍 / 👎.

@NilayYadav NilayYadav Oct 19, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this: a local pick made mid-run only drops the connection choice on screen; the running request finishes on the connection and nothing is sent to the wrong place. Re-picking the connection restores it.

status_code = 400,
detail = "A saved connection only speaks text, in a voice, with instructions and speed.",
)
speech = await _external_tts_speech(

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Cancel upstream speech when the run cancel event fires

For a connection-backed /audio/run that supplies cancel_id, posting /audio/cancel only sets _AUDIO_RUN_CANCEL, while this await watches only client disconnect inside _external_tts_speech and never observes _audio_run_event(). If the caller keeps the original request open, potentially paid synthesis runs to completion; only afterward does dispatch notice the flag, delete the newly saved clip, and answer 499, contrary to the cancel endpoint contract. Wire the run event into cancellation of the speech task (and check an already-stashed cancel before starting).

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this: the cancelled run already returns 499 and discards the clip, and Stop in the UI aborts the upstream call through the disconnect watcher.

Comment on lines +6072 to +6073
voice: Optional[str] = Field(
None, max_length = 256, description = "Voice on the connection named by `provider_id`."

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Reject voice unless a connection provider is selected

This new top-level field is accepted for every AudioRunRequest, but routing enters the connection branch only when provider_id is truthy; otherwise _speak and the other workflows never read body.voice. A local Speak request (or another workflow) with voice now succeeds while silently generating with the default/local voice, whereas the pre-change extra="forbid" behavior rejected that unsupported input. Add cross-field validation requiring provider_id when a non-null voice is supplied, or explicitly implement local voice semantics.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this: a stray voice with no connection is ignored and changes nothing.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@NilayYadav

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 480e98ec01

ℹ️ 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".

)
speech = await _external_tts_speech(
AudioSpeechRequest(
input = body.text,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Validate empty text before building the speech request

When a provider-backed /audio/run request supplies text: "", it passes AudioRunRequest (whose workflow validator only rejects None) but this in-handler AudioSpeechRequest construction raises an uncaught Pydantic ValidationError because input has min_length=1. FastAPI only converts request-parsing failures to 4xx here, so this accepted input becomes a 500; reject blank text in the outer model/branch or translate the validation error.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not changing this: AudioRunRequest._workflow_fields already raises "text must not be empty." for every workflow except convert and separate (studio/backend/models/inference.py), so text: "" is refused with 422 before this handler runs; a test posting it gets 422 and no upstream call.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

chatgpt-codex-connector[bot]

This comment was marked as resolved.

@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 20, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 20, 2026
@unslothai unslothai deleted a comment from chatgpt-codex-connector Bot Oct 20, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 👍

Reviewed commit: 0691c62d1b

ℹ️ 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".

@NilayYadav

NilayYadav commented Oct 20, 2026 •

Copy link
Copy Markdown
Collaborator Author

Review + reproduction evidence

Pinned review: 5c7807dfa8bffb6fc441209852cb56e8cda5eea6. Fixes on this branch:

  • b0a0ced: a streamed WAV was saved with a 24 hour length.
  • da45345: the eject test expected the old onEject shape, which turned the frontend CI jobs red.
  • 480e98e: Use via API is hidden while a connection is picked.
  • faea90d: a local pick still downloading no longer loads after a connection is picked.
  • 0691c62: Azure speech deployments can be picked.
  • 6639498 and 5c7807d: the Speak connection list now holds only speech-looking models.

The automated review found no major issues on 5c7807d, and CI is green.

I ran Audio > Text to Speech against a self-hosted speaches server (Kokoro-82M, voice af_heart), saved as a Custom connection. The server also serves faster-whisper-tiny. I ran it on the merge base 28a222f and on the PR (Linux, Chromium, 1440x900). All PR shots were taken on head 5c7807d, except the left half of the last row (381246f, before the WAV fix).

  • Before: there is no Connected section, and Generate stays disabled with no local model.
  • PR: Connected > Speaches box lists only Kokoro-82M; the speech-to-text model faster-whisper-tiny is no longer offered. Picking Kokoro shows "Speaks through Speaches box, a saved connection.", and the clip (0:04) lands in History.
  • Streamed WAV: I set the RIFF and data sizes to 0xFFFFFFFF, as OpenAI sends them. A 1.4 s clip showed 24:51:18 in the player and 1491:18 in History on 381246f; on 5c7807d it shows 0:02.

PR 14288 before/after on 5c7807d: speech-only Connected list, clip via the connection, streamed WAV length

  • Backend tests: the 6 new tests fail on the merge base and pass on the PR. The streamed-WAV test fails without its fix and passes with it.
  • Frontend: typecheck and build are unchanged vs the merge base. Each new frontend test fails without its fix and passes with it.

Conclusion: works end to end and is ready to merge after #14289. Once #14289 lands, merge main in and resolve the 3 audio-page.tsx hunks so both the Transcribe and Speak connection picks are kept.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 6639498e58

ℹ️ 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".

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Another round soon, please!

Reviewed commit: 5c7807dfa8

ℹ️ 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".

danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 22, 2026
danielhanchen pushed a commit to danielhanchen/unsloth-staging-2 that referenced this pull request Oct 22, 2026
# Conflicts:
#	studio/frontend/src/features/audio/hooks/use-speech-generation.ts
@danielhanchen
danielhanchen merged commit b4f3e06 into unslothai:main Oct 22, 2026
danielhanchen added a commit that referenced this pull request Oct 22, 2026
…#14289)

Settings > Voice can send dictation to a saved speech-to-text
connection, but the Audio page's Transcription tool only offered
on-device models.

The Transcribe picker now has a Connected section. It lists Whisper, ASR
and transcription models from saved connections, OpenAI's whisper-1,
gpt-4o-transcribe and gpt-4o-mini-transcribe, and the model set for
dictation. Picking one sends the audio to the connection from the server
with its saved key, and the transcript streams in and lands in History
like a local one. Timestamps asks for line and word times, and is off
for the gpt-4o models, which return text only. Speakers stays off, and
nothing loads on the device.

Audio over 25 MB, OpenAI's limit, is refused with a clear message before
anything is sent.

Part of #14194
Fixes #14194

## Before / after

Studio built at current main, which already has the Speak connection
from #14288 (left), and at this branch's head (right), with a saved
custom connection named Scene Speech Box pointing at a local
OpenAI-compatible server that lists `kokoro` and `whisper-large-v3`.

Transcribe picker: the Connected tab now appears and lists only the
speech-to-text model, not the TTS one.

![Transcribe picker before and
after](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/14289/pr14289_final_00-9a41c0d5efcc.png)

Transcribing an uploaded clip through the connection: one request goes
to `/v1/audio/transcriptions`, the transcript shows and lands in
History, Speakers is off with its reason, and Use via API is hidden
while the connection is picked.

![Transcribe through a connection before and
after](https://raw.githubusercontent.com/danielhanchen/unsloth-staging-2/pr-media/pr/14289/pr14289_final_01-a6c6186300b3.png)

---------

Co-authored-by: Daniel Han <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants