Repository navigation
Studio: complete the OpenAI-compatible audio API - #12812
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.
|
@codex review |
- 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.
|
@codex review |
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.
|
@codex review |
|
The |
|
A client with an API key can now use the Audio pages through What changed
Audio backend tests pass on |
|
Both red checks here are this PR's own. They pass on main 1fb38f9. |
…side verbose_json
|
Review record for #12812, carried over from the mirror it was reviewed on: danielhanchen/unsloth-staging-review#492. 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
|
…#12831) * Runtime encoding lint: follow another library's objects through with, methods and attributes The scan exempts .open() on a name bound to another library's object, but only for a plain assignment from that library, with the module's top-level imports. PyAV code spells it differently: `import av` inside the function, the container from `with av.open(...) as dst`, a stream from `dst.add_stream()`, and `stream.codec_context.open()`, which opens a codec and takes no encoding. That was reported as a Path.open() with no correct edit (seen on unslothai#12812). Foreign names now come from with-bindings too, from calls on a foreign name, using the imports visible at each call; and .open() on an attribute chain rooted at a foreign name is exempt. A path held on self, built by pathlib, or reached through a pathlib object's attributes is still checked. * Narrow runtime encoding exemption to PyAV codecs * Trim comments in runtime encoding guard * Key the PyAV codec exemption on path and expression, not line number --------- Co-authored-by: mahiatlinux <[email protected]>
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.
Summary
A script with an API key can now run the same audio workflows as the Audio pages through
/v1. Before,/v1/audio/speechignoredvoiceandspeedand only returned WAV, transcriptions had no timings, and/v1/audio/runalways used whatever model was already loaded and could not be fed audio from a/v1client./v1/audio/speechvoicetakes a saved voice id (a string or{"id": ...}) and speaks in that voice, using its stored transcript as the reference text. A built-in speaker the loaded model lists (for example Kokoro'saf_bella) goes intoaudio_options.voiceunless the request already set one. Other names, such as OpenAI'salloy, are still ignored.referenceandreference_textfields clone from an uploaded input, a history clip or a saved voice. Sending a saved voice and areferencetogether is a 400 withparam: "reference".response_formatacceptswav,mp3,flac,opus,aacandpcm, re-encoded with PyAV from the generated WAV. A format whose encoder is missing from the FFmpeg build returns a 400 that lists the formats that work.pcmis bare 24 kHz 16-bit little-endian mono samples, the format OpenAI's clients play. History still keeps the WAV.stream_format: "sse"returns a 400.speednow has OpenAI's 0.25 to 4.0 bounds and reaches models that support it./v1/audio/transcriptionsverbose_jsonreturns OpenAIsegments, andwordswhentimestamp_granularities[]=wordis sent.verbose_jsonno longer needslanguagewhen the model reports the language itself (Qwen3-ASR does; VibeVoice-ASR does not, so sendlanguagethere).diarized_jsonreturns speaker-labelled segments for models that can tell speakers apart (MOSS-Transcribe-Diarize, VibeVoice-ASR). Other models get the same 422 message the Transcribe page shows./v1/audio/runmodel. With model auto-switch on, a named model is loaded for any workflow. A model that cannot run the requested workflow (for exampleseparateon a TTS model) is refused with a 400param: "model"before the resident model is evicted. The check is a newrequire_audio_workflowargument to_maybe_auto_switch_model./v1/audio/generatecalls now appear in the API monitor. Runs from the Audio page and chat read-aloud do not.Audio inputs (
POST,GET .../file,DELETE), saved voices (CRUD and.../file) and history clip files now also answer on/v1, and the URLs those calls and/v1/audio/runreturn point at/v1./v1/audio/inputsgets the same streamed upload path and 200 MiB cap as the/api/inferenceroute, so it bypasses the general/v1body limit. These routes stay key-only, and the keyless route test now covers them./v1/audio/translationsand listing audio workflows in/v1/modelsare left for a follow-up to keep this one reviewable.Endpoints
POST /v1/audio/speechmodel,input,voice(saved voice id,{"id": ...}or a built-in speaker),reference+reference_textto clone,response_format(wav,mp3,flac,opus,aac,pcm),speed,instructions,language,seed,audio_optionsPOST /v1/audio/transcriptionsfile,model,language,response_format(json,text,verbose_json,diarized_json),timestamp_granularities[]on audio.cpp modelsPOST /v1/audio/runclone,speak,edit,convert,music,separate) withmodel, audio named byinput_id,clip_idorvoice_idPOST /v1/audio/inputs?name=...GET /v1/audio/inputs/{id}/file,DELETE /v1/audio/inputs/{id}GET,POST /v1/audio/voices;PATCH,DELETE /v1/audio/voices/{id};GET /v1/audio/voices/{id}/fileGET /v1/audio/gallery/{id}/filePOST /v1/audio/generateCompatibility
speedvalues outside 0.25 to 4.0 used to be accepted and ignored. They now fail validation. Avoicestring that matches a saved voice id or one of the loaded model's speakers now changes the output, where it was ignored before.Testing
Live run against a Studio server started from this branch on one GPU, calling
/v1with an API key through theopenaiPython SDK: 22/22 checks passed.wav,mp3,flac,opus,aac,pcm) with the expected file signatures and content types,pcmas bare samples, and a built-in voice changing the speaker./v1/audio/inputsupload,/v1/audio/voicescreate, then VoxCPM2 speech in that saved voice (as an object and as a string withmp3) and areferenceclone. Voice plus reference returned 400, andssereturned 400.verbose_jsonwith segments anddiarized_jsonwithSpeaker 1. Qwen3-ASRverbose_jsonwith nolanguagesent returned"English".diarized_jsonon Whisper returned the 422./v1/audio/runseparatenaming Kokoro was refused while VoxCPM2 stayed loaded. Naming HTDemucs auto-loaded it and returned four stems. A saved-voicespeakrun returned a/v1/audio/gallery/...URL./v1/audio/run,/v1/audio/speechand/v1/audio/transcriptions.Word timings on Qwen3-ASR need the aligner download and were not run live. Route tests with a faked sidecar cover them. The PyAV encoder was also checked against PyAV 12.3 (the requirement floor), 15 and 19.
Backend tests: 1435 passed, 1 skipped.
cd studio/backend python -m pytest -q \ tests/test_openai_audio_speech_route.py \ tests/test_openai_audio_transcriptions_route.py \ tests/test_audio_run_route.py \ tests/test_audio_inputs.py \ tests/test_audio_voices.py \ tests/test_openai_auto_switch.py \ tests/test_middleware.py \ tests/test_keyless_api_access.py \ tests/test_openai_audio_upload_bound.py \ tests/test_account_media_isolation.py \ tests/test_audio_cpp_separation.py \ tests/test_transcribe_source_route.py \ tests/test_stt_capabilities.py \ tests/test_api_monitor.py \ tests/test_audio_runtime_errors.pyThe multi-account suite and the audio clone, convert and edit request tests also pass (1071 passed).