Skip to content

Local UI to run and train LLMs and diffusion models. Supports GGUF, MLX, Qwen3.8, DeepSeek-V4.1, MiniMax-H3, Gemma 4, FLUX and more.

Studio: let Transcribe take larger and longer audio on audio.cpp models (#15952)

Etherl53eeebdc9be3
diff --git a/studio/backend/core/inference/audio_inputs.py b/studio/backend/core/inference/audio_inputs.py
index 27cb0cd0464..e251d3db297 100644
--- a/studio/backend/core/inference/audio_inputs.py
+++ b/studio/backend/core/inference/audio_inputs.py
@@ -22,22 +22,51 @@ from core.inference import audio_gallery
from loggers import get_logger
from utils.account_context import OWNER, AccountContext, is_owner_context, run_as
from utils.paths.storage_roots import account_path
-from utils.upload_limits import AUDIO_INPUT_MAX_BYTES
+from utils.upload_limits import audio_input_max_bytes
logger = get_logger(__name__)
MAX_SECONDS = 30 * 60
+# Uploads (and Transcribe on audio.cpp) take up to this; minutes in the env var override it.
+TRANSCRIBE_MAX_MINUTES_ENV = "UNSLOTH_STUDIO_TRANSCRIBE_MAX_MINUTES"
+DEFAULT_TRANSCRIBE_MAX_SECONDS = 4 * 60 * 60
TTL_SECONDS = 24 * 60 * 60
BYTE_CAP = 2 * 1024 * 1024 * 1024
REFERENCE_MAX_SECONDS = 30.0
REFERENCE_RATE = 24000
_MAX_CHANNELS = 2
-# Caps the stored rate so a 30 minute upload stays under ~350 MB however it was encoded.
+# Caps the stored rate so a 30 minute upload stays under ~350 MB however it was encoded;
+# longer uploads are refused once their WAV copy would pass BYTE_CAP.
MAX_RATE = 48000
_NAME_MAX = 255
_STALE_TMP_SECONDS = 60 * 60
+def transcribe_max_seconds() -> int:
+ """The longest upload, read per call; never under MAX_SECONDS."""
+ try:
+ minutes = int(os.environ.get(TRANSCRIBE_MAX_MINUTES_ENV, "").strip())
+ except ValueError:
+ minutes = 0
+ seconds = minutes * 60 if minutes > 0 else DEFAULT_TRANSCRIBE_MAX_SECONDS
+ return max(MAX_SECONDS, seconds)
+
+
+def length_words(seconds: float) -> str:
+ """``4 hours``, ``1 hour`` or ``90 minutes``."""
+ if seconds >= 3600 and seconds % 3600 == 0:
+ hours = int(seconds // 3600)
+ return "1 hour" if hours == 1 else f"{hours} hours"
+ return f"{int(seconds // 60)} minutes"
+
+
+def _size_words(nbytes: int) -> str:
+ gib = 1024 * 1024 * 1024
+ if nbytes >= gib and nbytes % gib == 0:
+ return f"{nbytes // gib} GB"
+ return f"{nbytes // (1024 * 1024)} MB"
+
+
class AudioInputError(ValueError):
"""A refusal with the HTTP status and plain reason the route sends."""
@@ -160,8 +189,10 @@ def transcode(
stereo: bool = False,
max_seconds: Optional[float] = None,
cut: bool = False,
+ max_bytes: Optional[int] = None,
) -> dict[str, Any]:
- """Streams through the FFmpeg resampler so a voice reference does not alias; past max_seconds it is cut if cut is set, else refused with 413."""
+ """Streams through the FFmpeg resampler so a voice reference does not alias; past max_seconds it is cut if cut is set, else refused with 413.
+ A WAV that would pass max_bytes is refused with 413."""
import av
max_seconds = MAX_SECONDS if max_seconds is None else max_seconds
@@ -174,8 +205,13 @@ def transcode(
for block in blocks:
take = min(block.samples, ceiling - frames)
if take < block.samples and not cut:
+ raise AudioInputError(413, f"Audio is longer than {length_words(max_seconds)}.")
+ if max_bytes is not None and (frames + take) * channels * 2 > max_bytes:
raise AudioInputError(
- 413, f"Audio is longer than {int(max_seconds // 60)} minutes."
+ 413,
+ "This audio is too long to keep: its WAV copy would pass the "
+ f"{_size_words(max_bytes)} an account can hold. Trim it, or upload it as "
+ "mono or at a lower sample rate.",
)
out.writeframesraw(block.to_ndarray().reshape(-1)[: take * channels].tobytes())
frames += take
@@ -306,7 +342,7 @@ async def save_stream(
"""The byte cap is checked per chunk, so an oversize upload is refused before it is read whole."""
import asyncio
- cap = AUDIO_INPUT_MAX_BYTES if max_bytes is None else max_bytes
+ cap = audio_input_max_bytes() if max_bytes is None else max_bytes
directory = inputs_dir()
tmp = directory / f".{uuid.uuid4().hex}.upload.tmp"
digest = hashlib.sha256()
@@ -317,14 +353,21 @@ async def save_stream(
if not chunk:
continue
size += len(chunk)
- if size > cap:
+ if cap is not None and size > cap:
raise AudioInputError(413, "Audio is too large.")
digest.update(chunk)
f.write(chunk)
if not size:
raise AudioInputError(400, "Audio is empty.")
return await asyncio.to_thread(
- _finish_upload, directory, tmp, digest.hexdigest(), _clean_name(name), size
+ _finish_upload,
+ directory,
+ tmp,
+ digest.hexdigest(),
+ _clean_name(name),
+ size,
+ max_seconds = transcribe_max_seconds(),
+ max_wav_bytes = BYTE_CAP,
)
finally:
tmp.unlink(missing_ok = True)
@@ -410,8 +453,11 @@ def _finish_upload(
size: int,
*,
prepared: Optional[dict[str, Any]] = None,
+ max_seconds: Optional[float] = None,
+ max_wav_bytes: Optional[int] = None,
) -> tuple[dict[str, Any], bool]:
- """``prepared``: ``tmp`` is already a ``transcode`` output with this info, so it is moved in as is."""
+ """``prepared``: ``tmp`` is already a ``transcode`` output with this info, so it is moved in
+ as is; otherwise it is transcoded under ``max_seconds`` and ``max_wav_bytes``."""
existing = _find_by_sha(directory, sha)
if existing is not None:
input_id, meta = existing
@@ -422,7 +468,7 @@ def _finish_upload(
wav = directory / f"{input_id}.wav"
try:
if prepared is None:
- info = transcode(tmp, wav)
+ info = transcode(tmp, wav, max_seconds = max_seconds, max_bytes = max_wav_bytes)
else:
os.replace(tmp, wav)
info = prepared
diff --git a/studio/backend/core/inference/stt_audiocpp_sidecar.py b/studio/backend/core/inference/stt_audiocpp_sidecar.py
index 410513ef36f..a980bd9af4c 100644
--- a/studio/backend/core/inference/stt_audiocpp_sidecar.py
+++ b/studio/backend/core/inference/stt_audiocpp_sidecar.py
@@ -75,6 +75,12 @@ logger = get_logger(__name__)
_TRANSCRIBE_TIMEOUT_SECONDS = 600.0
_DETAILS_PATH = "/v1/audio/transcriptions/details"
+
+def _transcribe_timeout(duration: Optional[float]) -> float:
+ """600 s, or twice the audio's length for anything past 5 minutes."""
+ return max(_TRANSCRIBE_TIMEOUT_SECONDS, 2.0 * (duration or 0))
+
+
# Fixed chunking keeps the runtime off its Silero VAD, which Studio does not ship.
QWEN3_ALIGNER = CompanionModel(
f"{AUDIO_CPP_REPO}/Qwen3-ForcedAligner-0.6B-GGUF",
@@ -1040,6 +1046,7 @@ class AudioCppSttSidecar:
sent,
cancel_event,
dict(_TIMESTAMP_OPTIONS) if aligned else {},
+ timeout = _transcribe_timeout(duration),
)
if cancel_event is not None and cancel_event.is_set():
raise SttTranscriptionCancelledError("Transcription cancelled.")
@@ -1078,6 +1085,8 @@ class AudioCppSttSidecar:
lang: Optional[str],
cancel_event: Optional[threading.Event],
options: dict,
+ *,
+ timeout: float = _TRANSCRIBE_TIMEOUT_SECONDS,
) -> dict:
server = self._server
if server is None:
@@ -1092,7 +1101,7 @@ class AudioCppSttSidecar:
return server.post_json(
_DETAILS_PATH,
request,
- timeout = _TRANSCRIBE_TIMEOUT_SECONDS,
+ timeout = timeout,
cancel_event = cancel_event,
)[1]
diff --git a/studio/backend/core/inference/stt_capabilities.py b/studio/backend/core/inference/stt_capabilities.py
index c149d07ba45..aa5b9160e5e 100644
--- a/studio/backend/core/inference/stt_capabilities.py
+++ b/studio/backend/core/inference/stt_capabilities.py
@@ -87,6 +87,16 @@ def _audio_cpp_family(model: str) -> Optional[str]:
return found.family if found and found.task == "asr" and not found.unsupported else None
+def max_seconds_for(engine: Optional[str]) -> int:
+ """The longest audio Transcribe takes on ``engine``; audio.cpp reads it whole."""
+ if engine == "audiocpp":
+ from core.inference import audio_inputs
+ return audio_inputs.transcribe_max_seconds()
+ from core.inference import stt_sidecar
+
+ return int(stt_sidecar._MAX_AUDIO_SECONDS)
+
+
def capabilities_for(model: Optional[str], engine: Optional[str]) -> dict:
"""``timestamps``: "on_request" | "always" | "unsupported"; ``aligner`` only for "on_request"."""
model = str(model or "").strip()
@@ -97,10 +107,12 @@ def capabilities_for(model: Optional[str], engine: Optional[str]) -> dict:
"speakers": False,
"aligner": None,
"cpu_only": False,
+ "max_seconds": None,
}
try:
resolved_engine = _engine_for(model, engine)
result["engine"] = resolved_engine
+ result["max_seconds"] = max_seconds_for(resolved_engine)
if resolved_engine != "audiocpp" or not model:
return result
family = _audio_cpp_family(model)
diff --git a/studio/backend/main.py b/studio/backend/main.py
index 4d356260366..76aa457187e 100644
--- a/studio/backend/main.py
+++ b/studio/backend/main.py
@@ -1488,7 +1488,6 @@ if _DOCS_ASSETS_DIR.is_dir():
# Cap request bodies on protected POSTs; upload routes get explicit multipart headroom.
import json as _json_for_413 # noqa: E402
from utils.upload_limits import ( # noqa: E402
- AUDIO_INPUT_MAX_BYTES,
STT_AUDIO_JSON_MAX_BYTES,
STT_AUDIO_RAW_MAX_BYTES,
LIBRARY_UPLOAD_MAX_BYTES,
@@ -1496,6 +1495,7 @@ from utils.upload_limits import ( # noqa: E402
UNSTRUCTURED_RECIPE_UPLOAD_MAX_BYTES,
VIDEO_INPUT_REFERENCE_JSON_MAX_BYTES,
VIDEO_INPUT_REFERENCE_MAX_BYTES,
+ audio_input_max_bytes,
default_request_body_limit_bytes,
upload_request_limit_bytes,
)
@@ -1589,7 +1589,9 @@ def _get_upload_passthrough_request_max_bytes(path: str) -> int:
if path.rstrip("/") == _LIBRARY_UPLOAD_PATH:
return upload_request_limit_bytes(LIBRARY_UPLOAD_MAX_BYTES)
if path.rstrip("/") in _AUDIO_INPUT_UPLOAD_PATHS:
- return AUDIO_INPUT_MAX_BYTES
+ # None means no cap, as the route treats it.
+ cap = audio_input_max_bytes()
+ return sys.maxsize if cap is None else cap
if _SANDBOX_UPLOAD_RE.match(path):
return upload_request_limit_bytes(SANDBOX_UPLOAD_MAX_BYTES)
if _RAG_DOCUMENT_UPLOAD_RE.match(path):
diff --git a/studio/backend/routes/inference.py b/studio/backend/routes/inference.py
index 04d59f4a5fd..aeff22ebf9c 100644
--- a/studio/backend/routes/inference.py
+++ b/studio/backend/routes/inference.py
@@ -25785,6 +25785,27 @@ async def _external_source_transcript(
return _source_transcript(result, source, False)
+def _refuse_long_source(
+ source,
+ cap: float,
+ *,
+ connection: bool = False,
+) -> None:
+ """413 before any model load or upload when the source runs past ``cap`` seconds."""
+ from core.inference import audio_edit, audio_inputs
+
+ seconds = audio_edit.wav_seconds(source.path)
+ if seconds is None or seconds <= cap:
+ return
+ who = "A connection takes" if connection else "This model transcribes"
+ longest = audio_inputs.length_words(audio_inputs.transcribe_max_seconds())
+ raise audio_inputs.AudioInputError(
+ 413,
+ f"{who} up to {audio_inputs.length_words(cap)} of audio. Trim it, or pick an audio.cpp "
+ f"model, which takes up to {longest}.",
+ )
+
+
@studio_router.post("/audio/transcribe/source")
async def transcribe_audio_source(
body: TranscribeSourceRequest,
@@ -25796,10 +25817,14 @@ async def transcribe_audio_source(
from core.inference.transcript_stream import stream_transcript
if body.provider_id is not None:
+
+ def _resolve():
+ source = audio_inputs.resolve_source(body.source.model_dump(exclude_none = True))
+ _refuse_long_source(source, stt_capabilities.max_seconds_for(None), connection = True)
+ return source
+
try:
- source = await asyncio.to_thread(
- audio_inputs.resolve_source, body.source.model_dump(exclude_none = True)
- )
+ source = await asyncio.to_thread(_resolve)
except audio_inputs.AudioInputError as exc:
raise _audio_source_error(exc) from None
return StreamingResponse(
@@ -25816,10 +25841,12 @@ async def transcribe_audio_source(
caps = await asyncio.to_thread(stt_capabilities.capabilities_for, body.model, serving_engine)
_refuse_stt_caps(caps, timestamps = body.timestamps, speakers = body.speakers)
rate = stt_details.FIXED_SPAN_RATES.get(caps["family"], 16000)
+ cap = stt_capabilities.max_seconds_for(serving_engine)
def _prepare():
source = audio_inputs.resolve_source(body.source.model_dump(exclude_none = True))
- return source, audio_inputs.prepared_path(source, rate)
+ _refuse_long_source(source, cap)
+ return source, audio_inputs.prepared_path(source, rate, cap)
try:
source, path = await asyncio.to_thread(_prepare)
@@ -49448,11 +49475,12 @@ async def upload_audio_input(
"""Store a raw audio body (any container), decoded once to WAV; a re-upload of the same audio
returns the existing record with 200."""
from core.inference import audio_inputs
- from utils.upload_limits import AUDIO_INPUT_MAX_BYTES
+ from utils.upload_limits import audio_input_max_bytes
+ cap = audio_input_max_bytes()
declared = request.headers.get("content-length")
try:
- if declared is not None and int(declared) > AUDIO_INPUT_MAX_BYTES:
+ if cap is not None and declared is not None and int(declared) > cap:
raise HTTPException(status_code = 413, detail = "Audio is too large.")
except ValueError:
pass
diff --git a/studio/backend/routes/settings.py b/studio/backend/routes/settings.py
index 34e16f1c548..a6acc0c24c9 100644
--- a/studio/backend/routes/settings.py
+++ b/studio/backend/routes/settings.py
@@ -71,6 +71,7 @@ from utils.personalization_settings import (
from utils.upload_limits import (
MAX_UPLOAD_LIMIT_MB,
MIN_UPLOAD_LIMIT_MB,
+ audio_input_max_bytes,
default_upload_limit_mb,
get_upload_limit_mb,
set_upload_limit_mb,
@@ -593,6 +594,8 @@ class UploadLimitResponse(BaseModel):
default_upload_size_mb: int
min_upload_size_mb: int = MIN_UPLOAD_LIMIT_MB
max_allowed_upload_size_mb: int = MAX_UPLOAD_LIMIT_MB
+ # Audio page upload cap; None means no cap.
+ audio_input_max_bytes: Optional[int] = None
class ToolResultLimitPayload(BaseModel):
@@ -1168,6 +1171,7 @@ def _upload_limit_response(limit_mb: int) -> UploadLimitResponse:
max_upload_size_bytes = upload_limit_bytes(limit_mb),
max_upload_size_label = upload_limit_label(limit_mb),
default_upload_size_mb = default_upload_limit_mb(),
+ audio_input_max_bytes = audio_input_max_bytes(limit_mb),
)
diff --git a/studio/backend/tests/test_audio_inputs.py b/studio/backend/tests/test_audio_inputs.py
index 9778d3e0950..a4ae66e166e 100644
--- a/studio/backend/tests/test_audio_inputs.py
+++ b/studio/backend/tests/test_audio_inputs.py
@@ -196,8 +196,18 @@ def test_an_oversize_body_is_refused_while_streaming():
@pytest.mark.parametrize(
"patches, make, status, detail",
[
- ({"AUDIO_INPUT_MAX_BYTES": 2048}, lambda: wav_bytes(2.0), 413, "Audio is too large."),
- ({"MAX_SECONDS": 1}, lambda: wav_bytes(2.0), 413, "Audio is longer than 0 minutes."),
+ (
+ {"audio_input_max_bytes": lambda: 2048},
+ lambda: wav_bytes(2.0),
+ 413,
+ "Audio is too large.",
+ ),
+ (
+ {"transcribe_max_seconds": lambda: 1},
+ lambda: wav_bytes(2.0),
+ 413,
+ "Audio is longer than 0 minutes.",
+ ),
({}, lambda: b"", 400, "Audio is empty."),
({}, lambda: b"not audio " * 120, 400, "This file is not audio Unsloth can read."),
({}, _video_without_audio, 400, "This file has no audio stream."),
@@ -212,15 +222,130 @@ def test_bad_or_over_cap_uploads_are_refused(client, monkeypatch, patches, make,
assert not list(audio_inputs.inputs_dir().glob("*.wav"))
-def test_the_body_middleware_passes_the_upload_through_at_its_own_cap():
+def test_the_body_middleware_passes_the_upload_through_at_its_own_cap(monkeypatch):
import main
+ monkeypatch.delenv(limits.AUDIO_INPUT_MAX_UPLOAD_MB_ENV, raising = False)
assert limits.AUDIO_INPUT_MAX_BYTES == 200 * 1024 * 1024
for path in (INPUTS, f"{INPUTS}/"):
- assert main._get_upload_passthrough_request_max_bytes(path) == limits.AUDIO_INPUT_MAX_BYTES
+ cap = main._get_upload_passthrough_request_max_bytes(path)
+ assert cap == limits.audio_input_max_bytes()
assert f"{INPUTS}/x/transcribe" not in main._BODY_UPLOAD_PASSTHROUGH_EXACT_PATHS
+def kib_limits(monkeypatch):
+ """Upload limits in KiB rather than MiB, so a few seconds of WAV crosses them."""
+ monkeypatch.delenv(limits.AUDIO_INPUT_MAX_UPLOAD_MB_ENV, raising = False)
+ monkeypatch.setattr(limits, "_BYTES_PER_MB", 1024)
+ monkeypatch.setattr(limits, "AUDIO_INPUT_MAX_BYTES", 200 * 1024)
+ setting = {"mb": 300}
+ monkeypatch.setattr(limits, "get_upload_limit_mb", lambda: setting["mb"])
+ return setting
+
+
[email protected]("setting, cap", [(300, 300 * 1024), (100, 200 * 1024)])
+def test_the_audio_cap_follows_the_upload_setting_above_its_floor(client, kib_limits, setting, cap):
+ import main
+
+ kib_limits["mb"] = setting
+ assert limits.audio_input_max_bytes() == cap
+ assert main._get_upload_passthrough_request_max_bytes(INPUTS) == cap
+ fits, over_floor = wav_bytes(6.0), wav_bytes(9.0) # ~188 KiB and ~281 KiB
+ assert len(fits) < 200 * 1024 < len(over_floor) < 300 * 1024
+ assert _upload(client, fits, "a.wav").status_code == 201
+ response = _upload(client, over_floor, "b.wav")
+ assert response.status_code == (201 if setting == 300 else 413), response.text
+ with pytest.raises(audio_inputs.AudioInputError) as refused:
+ asyncio.run(audio_inputs.save_stream(_chunks([b"\x00" * (cap + 1)]), "d.wav"))
+ assert (refused.value.status, refused.value.detail) == (413, "Audio is too large.")
+
+
+ "env, cap",
+ [("0", None), ("2", 2 * 1024), ("abc", 300 * 1024), ("-1", 300 * 1024), ("", 300 * 1024)],
+)
+def test_the_audio_cap_env_overrides_the_setting_exactly(kib_limits, monkeypatch, env, cap):
+ import sys
+
+ import main
+ from routes.settings import _upload_limit_response
+
+ monkeypatch.setenv(limits.AUDIO_INPUT_MAX_UPLOAD_MB_ENV, env)
+ assert limits.audio_input_max_bytes() == cap
+ passthrough = main._get_upload_passthrough_request_max_bytes(INPUTS)
+ assert passthrough == (sys.maxsize if cap is None else cap)
+ assert _upload_limit_response(300).audio_input_max_bytes == cap
+
+
+def test_no_audio_cap_takes_any_size(client, kib_limits, monkeypatch):
+ monkeypatch.setenv(limits.AUDIO_INPUT_MAX_UPLOAD_MB_ENV, "0")
+ big = wav_bytes(20.0)
+ assert len(big) > 300 * 1024
+ assert _upload(client, big, "big.wav").status_code == 201
+
+
+def test_the_upload_limit_settings_name_the_audio_cap(monkeypatch):
+ from routes.settings import _upload_limit_response
+
+ monkeypatch.delenv(limits.AUDIO_INPUT_MAX_UPLOAD_MB_ENV, raising = False)
+ assert _upload_limit_response(1000).audio_input_max_bytes == 1000 * 1024 * 1024
+ assert _upload_limit_response(100).audio_input_max_bytes == 200 * 1024 * 1024
+
+
+ "env, seconds", [("90", 5400), ("10", 1800), ("abc", 14400), ("0", 14400), ("-5", 14400)]
+)
+def test_the_longest_upload_reads_its_env_in_minutes(monkeypatch, env, seconds):
+ monkeypatch.setenv(audio_inputs.TRANSCRIBE_MAX_MINUTES_ENV, env)
+ assert audio_inputs.transcribe_max_seconds() == seconds
+
+
+ "seconds, words",
+ [
+ (14400, "4 hours"),
+ (3600, "1 hour"),
+ (5400, "90 minutes"),
+ (1800, "30 minutes"),
+ (1, "0 minutes"),
+ ],
+)
+def test_lengths_read_in_hours_or_minutes(seconds, words):
+ assert audio_inputs.length_words(seconds) == words
+
+
+def test_an_upload_past_the_old_30_minutes_is_kept(client, monkeypatch):
+ monkeypatch.delenv(audio_inputs.TRANSCRIBE_MAX_MINUTES_ENV, raising = False)
+ monkeypatch.setattr(audio_inputs, "MAX_SECONDS", 1)
+ response = _upload(client, wav_bytes(2.0), "long.wav")
+ assert response.status_code == 201, response.text
+ assert response.json()["duration_s"] == pytest.approx(2.0)
+
+
+def test_an_upload_whose_wav_would_pass_the_store_cap_is_refused(client, monkeypatch):
+ monkeypatch.setattr(audio_inputs, "BYTE_CAP", 20000)
+ response = _upload(client, wav_bytes(1.0), "big.wav")
+ assert response.status_code == 413
+ assert response.json()["detail"].startswith("This audio is too long to keep: its WAV copy")
+ assert not list(audio_inputs.inputs_dir().iterdir())
+ monkeypatch.setattr(audio_inputs, "BYTE_CAP", 64000)
+ assert _upload(client, wav_bytes(1.0), "fits.wav").status_code == 201
+
+
+def test_the_store_cap_reads_in_gb():
+ assert audio_inputs._size_words(audio_inputs.BYTE_CAP) == "2 GB"
+
+
+def test_media_audio_keeps_the_30_minute_cap(tmp_path, monkeypatch):
+ monkeypatch.setattr(audio_inputs, "MAX_SECONDS", 1)
+ src = tmp_path / "clip.wav"
+ src.write_bytes(wav_bytes(2.0))
+ with pytest.raises(audio_inputs.AudioInputError) as refused:
+ audio_inputs.save_from_media(src, "clip")
+ assert refused.value.status == 413
+
+
def test_the_sweep_drops_the_oldest_past_the_byte_cap_then_all_past_the_ttl(client, monkeypatch):
clock = [1_000_000.0]
monkeypatch.setattr(audio_inputs, "_now", lambda: clock[0])
diff --git a/studio/backend/tests/test_middleware.py b/studio/backend/tests/test_middleware.py
index e8a00d09e9a..5154014e8df 100644
--- a/studio/backend/tests/test_middleware.py
+++ b/studio/backend/tests/test_middleware.py
@@ -163,12 +163,12 @@ class TestMaxBodyMiddleware:
assert main_module._get_upload_passthrough_request_max_bytes(path + "/") == (
upload_request_limit_bytes(STT_AUDIO_RAW_MAX_BYTES)
), path
- from utils.upload_limits import AUDIO_INPUT_MAX_BYTES
+ from utils.upload_limits import audio_input_max_bytes
for path in ("/v1/audio/inputs", "/api/inference/audio/inputs"):
assert path in main_module._BODY_UPLOAD_PASSTHROUGH_EXACT_PATHS, path
assert main_module._get_upload_passthrough_request_max_bytes(path) == (
- AUDIO_INPUT_MAX_BYTES
+ audio_input_max_bytes()
), path
from utils.upload_limits import (
VIDEO_INPUT_REFERENCE_JSON_MAX_BYTES,
diff --git a/studio/backend/tests/test_stt_audiocpp_details.py b/studio/backend/tests/test_stt_audiocpp_details.py
index 1060fe9b505..33dc25c3074 100644
--- a/studio/backend/tests/test_stt_audiocpp_details.py
+++ b/studio/backend/tests/test_stt_audiocpp_details.py
@@ -261,6 +261,24 @@ def test_other_families_keep_the_bare_code(fake, side, source):
assert [body["language"] for body in fake.bodies] == ["ja", "en", "en"]
[email protected]("duration, timeout", [(2.0, 600.0), (300.0, 600.0), (7200.0, 14400.0)])
+def test_the_transcribe_timeout_grows_with_long_audio(
+ fake, side, source, monkeypatch, duration, timeout
+):
+ seen = []
+ real = srv.AudioCppServer.post_json
+
+ def post_json(self, path, payload, **kwargs):
+ seen.append(kwargs.get("timeout"))
+ return real(self, path, payload, **kwargs)
+
+ monkeypatch.setattr(srv.AudioCppServer, "post_json", post_json)
+ monkeypatch.setattr(stt, "_wav_rate_and_duration", lambda _path: (16000, duration))
+ side.transcribe_path(source, QWEN3, None)
+ assert stt._transcribe_timeout(duration) == timeout
+ assert seen == [timeout]
+
+
def test_parakeet_switches_to_bounded_windows_on_long_audio(fake, side, source):
side.transcribe_path(source, PARAKEET, None)
(start,) = fake.starts
diff --git a/studio/backend/tests/test_stt_capabilities.py b/studio/backend/tests/test_stt_capabilities.py
index 512ff9af531..fc3126fc653 100644
--- a/studio/backend/tests/test_stt_capabilities.py
+++ b/studio/backend/tests/test_stt_capabilities.py
@@ -80,7 +80,10 @@ def test_qwen3_reports_whether_its_aligner_is_downloaded(hub):
(f"{REPO}/Qwen3-ASR-0.6B-GGUF", "no-such-engine", None),
],
)
-def test_other_engines_and_unknown_models_are_plain_text(hub, model, engine, expected_engine):
+def test_other_engines_and_unknown_models_are_plain_text(
+ hub, monkeypatch, model, engine, expected_engine
+):
+ monkeypatch.delenv("UNSLOTH_STUDIO_TRANSCRIBE_MAX_MINUTES", raising = False)
result = caps.capabilities_for(model, engine)
assert result == {
"engine": expected_engine,
@@ -89,9 +92,30 @@ def test_other_engines_and_unknown_models_are_plain_text(hub, model, engine, exp
"speakers": False,
"aligner": None,
"cpu_only": False,
+ "max_seconds": 4 * 3600 if expected_engine == "audiocpp" else 30 * 60,
}
+ "model, engine, env, seconds",
+ [
+ (f"{REPO}/Qwen3-ASR-0.6B-GGUF", "audiocpp", None, 14400),
+ (f"{REPO}/Qwen3-ASR-0.6B-GGUF", "audiocpp", "90", 5400),
+ ("small", "transformers", "90", 1800),
+ ("small", "gguf", None, 1800),
+ ],
+)
+def test_each_engine_reports_the_longest_audio_it_takes(
+ hub, monkeypatch, model, engine, env, seconds
+):
+ if env is None:
+ monkeypatch.delenv("UNSLOTH_STUDIO_TRANSCRIBE_MAX_MINUTES", raising = False)
+ else:
+ monkeypatch.setenv("UNSLOTH_STUDIO_TRANSCRIBE_MAX_MINUTES", env)
+ assert caps.capabilities_for(model, engine)["max_seconds"] == seconds
+ assert caps.max_seconds_for(engine) == seconds
+
+
def test_a_failing_lookup_still_answers(hub, monkeypatch):
def broken(*_args, **_kwargs):
raise OSError("cache unreadable")
diff --git a/studio/backend/tests/test_transcribe_source_route.py b/studio/backend/tests/test_transcribe_source_route.py
index 569c1ab3054..22aee186878 100644
--- a/studio/backend/tests/test_transcribe_source_route.py
+++ b/studio/backend/tests/test_transcribe_source_route.py
@@ -303,3 +303,58 @@ def test_a_source_past_the_connection_limit_is_refused_before_upload(stub, conne
assert events[-1]["type"] == "error"
assert "a connection takes" in events[-1]["message"]
assert not connection and not stub.bytes
+
+
+def _long_input(account, seconds = 3.0) -> str:
+ save = audio_inputs.save_stream(_chunks([wav_bytes(seconds)]), "long.wav")
+ return run_as(account, lambda: asyncio.run(save)[0]["id"])
+
+
+def short_caps(monkeypatch):
+ from core.inference import stt_sidecar
+
+ monkeypatch.delenv(audio_inputs.TRANSCRIBE_MAX_MINUTES_ENV, raising = False)
+ monkeypatch.setattr(audio_inputs, "MAX_SECONDS", 1)
+ monkeypatch.setattr(stt_sidecar, "_MAX_AUDIO_SECONDS", 1)
+
+
+def test_audio_cpp_reads_the_whole_source_past_the_other_engines_cap(stub, short_caps):
+ input_id = _long_input(ALICE)
+ with _client(ALICE) as client:
+ response, events = _post(client, source = {"input_id": input_id})
+ assert response.status_code == 200, response.text
+ ((path, rate, _, _),) = stub.paths
+ assert path.name == f"{input_id}.16000.mono.m14400.wav"
+ with wave.open(str(path)) as w:
+ assert w.getnframes() / w.getframerate() == pytest.approx(3.0, abs = 0.05)
+ assert events[-1]["type"] == "complete"
+
+
+def test_another_engine_refuses_a_source_past_its_cap_before_loading(stub, short_caps):
+ source = {"input_id": _long_input(ALICE)}
+ with _client(ALICE) as client:
+ response, _ = _post(client, model = "small", engine = "transformers", source = source)
+ assert response.status_code == 413
+ assert response.json()["detail"] == (
+ "This model transcribes up to 0 minutes of audio. Trim it, or pick an audio.cpp model, "
+ "which takes up to 4 hours."
+ )
+ assert not (stub.loads or stub.bytes or stub.paths)
+
+
+def test_a_source_just_past_the_cap_is_refused_not_cut(stub, short_caps):
+ source = {"input_id": _long_input(ALICE, seconds = 1.5)}
+ with _client(ALICE) as client:
+ response, _ = _post(client, model = "small", engine = "transformers", source = source)
+ assert response.status_code == 413
+ assert not (stub.loads or stub.bytes or stub.paths)
+
+
+def test_a_connection_refuses_a_source_past_its_cap_before_upload(stub, connection, short_caps):
+ source = {"input_id": _long_input(ALICE)}
+ with _client(ALICE) as client:
+ response, _ = _post(client, provider_id = "conn-1", model = "whisper-1", source = source)
+ assert response.status_code == 413
+ assert response.json()["detail"].startswith("A connection takes up to 0 minutes of audio.")
+ assert connection == [] and not (stub.loads or stub.bytes)
diff --git a/studio/backend/utils/upload_limits.py b/studio/backend/utils/upload_limits.py
index c09c333da97..1e5229e550c 100644
--- a/studio/backend/utils/upload_limits.py
+++ b/studio/backend/utils/upload_limits.py
@@ -86,6 +86,24 @@ def get_upload_limit_bytes() -> int:
return upload_limit_bytes()
+AUDIO_INPUT_MAX_UPLOAD_MB_ENV = "UNSLOTH_STUDIO_AUDIO_MAX_UPLOAD_MB"
+
+
+def audio_input_max_bytes(limit_mb: int | None = None) -> int | None:
+ """Audio page upload cap: the upload setting, never under AUDIO_INPUT_MAX_BYTES.
+ UNSLOTH_STUDIO_AUDIO_MAX_UPLOAD_MB sets it exactly; 0 means no cap (None)."""
+ raw = os.environ.get(AUDIO_INPUT_MAX_UPLOAD_MB_ENV, "").strip()
+ try:
+ env_mb = int(raw) if raw else None
+ except ValueError:
+ env_mb = None
+ if env_mb == 0:
+ return None
+ if env_mb is not None and env_mb > 0:
+ return env_mb * _BYTES_PER_MB
+ return max(AUDIO_INPUT_MAX_BYTES, upload_limit_bytes(limit_mb))
+
+
def upload_limit_label(limit_mb: int | None = None) -> str:
return f"{limit_mb if limit_mb is not None else get_upload_limit_mb()}MB"
diff --git a/studio/frontend/src/features/audio/audio-run-request.ts b/studio/frontend/src/features/audio/audio-run-request.ts
index ed52d2eb712..8c32928c3d9 100644
--- a/studio/frontend/src/features/audio/audio-run-request.ts
+++ b/studio/frontend/src/features/audio/audio-run-request.ts
@@ -3,7 +3,8 @@
// No app imports: the node test runner loads this directly. Clients send ids only, never paths or audio.
-/** Mirrors AUDIO_INPUT_MAX_BYTES in studio/backend/utils/upload_limits.py. */
+/** Mirrors AUDIO_INPUT_MAX_BYTES in studio/backend/utils/upload_limits.py: the floor of the
+ * server's audio cap, used until /api/settings/upload-limit answers. */
export const AUDIO_INPUT_MAX_BYTES = 200 * 1024 * 1024;
export const REFERENCE_MAX_SECONDS = 30;
diff --git a/studio/frontend/src/features/audio/hooks/audio-source-state.ts b/studio/frontend/src/features/audio/hooks/audio-source-state.ts
index 0aa173eceea..cccffaa0e4b 100644
--- a/studio/frontend/src/features/audio/hooks/audio-source-state.ts
+++ b/studio/frontend/src/features/audio/hooks/audio-source-state.ts
@@ -144,14 +144,18 @@ export function audioSourceReducer(
}
}
-export function audioFileProblem(file: {
- size: number;
- type?: string;
- name?: string;
-}): string | null {
+/** `maxBytes` null: the server takes any size. */
+export function audioFileProblem(
+ file: {
+ size: number;
+ type?: string;
+ name?: string;
+ },
+ maxBytes: number | null = AUDIO_INPUT_MAX_BYTES,
+): string | null {
if (file.size <= 0) return "This file is empty.";
- if (file.size > AUDIO_INPUT_MAX_BYTES)
- return "Audio is too large. Keep it under 200 MB.";
+ if (maxBytes !== null && file.size > maxBytes)
+ return `Audio is too large. Keep it under ${Math.floor(maxBytes / 2 ** 20)} MB.`;
const type = file.type ?? "";
const name = (file.name ?? "").toLowerCase();
if (
diff --git a/studio/frontend/src/features/audio/hooks/use-audio-source.ts b/studio/frontend/src/features/audio/hooks/use-audio-source.ts
index f24a0b76dd1..b9a674469e3 100644
--- a/studio/frontend/src/features/audio/hooks/use-audio-source.ts
+++ b/studio/frontend/src/features/audio/hooks/use-audio-source.ts
@@ -6,11 +6,13 @@ import {
createAudioRecorder,
} from "@/features/chat/adapters/pcm-recorder";
import { isMissingDeviceError } from "@/features/chat/adapters/studio-web-speech-dictation-adapter";
+import { loadUploadLimitSettings } from "@/features/settings";
import { useVoiceSettingsStore } from "@/features/settings/stores/voice-settings-store";
import { isTauri } from "@/lib/api-base";
import { useCallback, useEffect, useReducer, useRef, useState } from "react";
import { AudioApiError, fetchAudioBlob, uploadAudioInput } from "../api";
import {
+ AUDIO_INPUT_MAX_BYTES,
type AudioSourceSelection,
selectionExpired,
sourceFileUrl,
@@ -200,11 +202,18 @@ export function useAudioSource({
async (file: File | Blob, name?: string) => {
const fileName =
name ?? ("name" in file && file.name ? file.name : "Recording");
- const problem = audioFileProblem({
- size: file.size,
- type: file.type,
- name: fileName,
- });
+ // The server's cap follows the upload setting; the floor stands in until it answers.
+ const maxBytes = await loadUploadLimitSettings().then(
+ (settings) =>
+ settings.audioInputMaxBytes === undefined
+ ? AUDIO_INPUT_MAX_BYTES
+ : settings.audioInputMaxBytes,
+ () => AUDIO_INPUT_MAX_BYTES,
+ );
+ const problem = audioFileProblem(
+ { size: file.size, type: file.type, name: fileName },
+ maxBytes,
+ );
if (problem) {
dispatch({ type: "fail", message: problem });
return;
diff --git a/studio/frontend/src/features/audio/pages/transcribe-page.tsx b/studio/frontend/src/features/audio/pages/transcribe-page.tsx
index 9a7ab9d0d63..17d2d56fdf9 100644
--- a/studio/frontend/src/features/audio/pages/transcribe-page.tsx
+++ b/studio/frontend/src/features/audio/pages/transcribe-page.tsx
@@ -151,7 +151,7 @@ export function TranscribeRail({
<AudioSourceInput
id="transcribe-source"
label="Audio"
- hint="Up to 30 minutes. Drop a file, record, or reuse a clip."
+ hint={switches.sourceHint}
value={source}
onChange={(next) => useAudioTranscribeStore.setState({ source: next })}
disabled={disabled}
diff --git a/studio/frontend/src/features/audio/transcribe-capabilities.ts b/studio/frontend/src/features/audio/transcribe-capabilities.ts
index c2e01af1b22..a3a62572aeb 100644
--- a/studio/frontend/src/features/audio/transcribe-capabilities.ts
+++ b/studio/frontend/src/features/audio/transcribe-capabilities.ts
@@ -16,6 +16,8 @@ export interface SttCapabilities {
variant?: string;
} | null;
cpu_only: boolean;
+ /** The longest audio this model takes; missing from an older backend. */
+ max_seconds?: number | null;
}
export interface TranscribeSwitch {
@@ -31,10 +33,26 @@ export interface TranscribeSwitches {
speakers: TranscribeSwitch;
notice: string | null;
request: { timestamps: boolean; speakers: boolean };
+ sourceHint: string;
}
export const SPEAKERS_MODEL_NAME = "MOSS-Transcribe-Diarize";
+function lengthWords(seconds: number): string {
+ if (seconds >= 3600 && seconds % 3600 === 0) {
+ const hours = seconds / 3600;
+ return hours === 1 ? "1 hour" : `${hours} hours`;
+ }
+ return `${Math.floor(seconds / 60)} minutes`;
+}
+
+/** The source card's hint; without a model's limit it keeps the 30 minutes every engine takes. */
+export function transcribeSourceHint(maxSeconds?: number | null): string {
+ if (maxSeconds == null)
+ return "Up to 30 minutes. Drop a file, record, or reuse a clip.";
+ return `Up to ${lengthWords(maxSeconds)} with this model. Drop a file, record, or reuse a clip.`;
+}
+
/** The aligner download a timestamped run needs first, staged like any other quant so it shows in
* the Downloads panel; null when the run can start now. */
export function alignerDownloadEntry(
@@ -131,6 +149,7 @@ export function connectionTranscribeSwitches(
},
notice: null,
request: { timestamps: !untimed && prefs.timestamps, speakers: false },
+ sourceHint: transcribeSourceHint(null),
};
}
@@ -151,6 +170,7 @@ export function transcribeSwitches(
speakers: off,
notice: null,
request: { timestamps: false, speakers: false },
+ sourceHint: transcribeSourceHint(null),
};
}
@@ -205,5 +225,11 @@ export function transcribeSwitches(
: aligner
? `${aligner} Runs on the CPU.`
: "This model runs on the CPU.";
- return { timestamps, speakers, notice, request };
+ return {
+ timestamps,
+ speakers,
+ notice,
+ request,
+ sourceHint: transcribeSourceHint(caps.max_seconds),
+ };
}
diff --git a/studio/frontend/src/features/settings/api/upload-limit.ts b/studio/frontend/src/features/settings/api/upload-limit.ts
index f7e2d267596..47fe2544ef5 100644
--- a/studio/frontend/src/features/settings/api/upload-limit.ts
+++ b/studio/frontend/src/features/settings/api/upload-limit.ts
@@ -16,6 +16,8 @@ export type UploadLimitSettings = {
defaultUploadSizeMb: number;
minUploadSizeMb: number;
maxAllowedUploadSizeMb: number;
+ /** The Audio page upload cap; null means none, undefined an older backend. */
+ audioInputMaxBytes?: number | null;
};
type ApiUploadLimitSettings = {
@@ -31,6 +33,8 @@ type ApiUploadLimitSettings = {
min_upload_size_mb: number;
// biome-ignore lint/style/useNamingConvention: API schema
max_allowed_upload_size_mb: number;
+ // biome-ignore lint/style/useNamingConvention: API schema
+ audio_input_max_bytes?: number | null;
};
let cachedUploadLimit: UploadLimitSettings | null = null;
@@ -68,6 +72,7 @@ function fromApi(settings: ApiUploadLimitSettings): UploadLimitSettings {
defaultUploadSizeMb: settings.default_upload_size_mb,
minUploadSizeMb: settings.min_upload_size_mb,
maxAllowedUploadSizeMb: settings.max_allowed_upload_size_mb,
+ audioInputMaxBytes: settings.audio_input_max_bytes,
};
}
diff --git a/studio/frontend/tests/audio-page-policy.test.ts b/studio/frontend/tests/audio-page-policy.test.ts
index 3a19504b866..8a744469199 100644
--- a/studio/frontend/tests/audio-page-policy.test.ts
+++ b/studio/frontend/tests/audio-page-policy.test.ts
@@ -533,7 +533,7 @@ test("Record is offered only where the browser can capture audio", () => {
});
test("a Transcribe recording is stopped at the 30 minute limit the inputs route accepts", () => {
- // 30 minutes of 16 kHz PCM is ~58 MB, under the 200 MB backend cap.
+ // 30 minutes of 16 kHz PCM is ~58 MB, under the backend cap's 200 MB floor.
assert.match(audioPageSource, /const RECORDING_MAX_SECONDS = 30 \* 60;/);
assert.match(audioPageSource, /maxRecordSeconds=\{RECORDING_MAX_SECONDS\}/);
assert.match(
diff --git a/studio/frontend/tests/audio-source-input.test.ts b/studio/frontend/tests/audio-source-input.test.ts
index dd23719a800..5d11445b43e 100644
--- a/studio/frontend/tests/audio-source-input.test.ts
+++ b/studio/frontend/tests/audio-source-input.test.ts
@@ -164,7 +164,7 @@ test("recording starts and stops back to the empty card", () => {
assert.match(hook, /createAudioRecorder\(stream\)/);
});
-test("a too-large or empty file is refused before any upload, at the server's 200 MiB", () => {
+test("a too-large or empty file is refused before any upload, at the server's cap", () => {
assert.equal(AUDIO_INPUT_MAX_BYTES, 200 * 1024 * 1024);
assert.equal(
audioFileProblem({ size: AUDIO_INPUT_MAX_BYTES, type: "audio/wav" }),
@@ -178,6 +178,26 @@ test("a too-large or empty file is refused before any upload, at the server's 20
audioFileProblem({ size: 0, type: "audio/wav" }),
"This file is empty.",
);
+ // The server's cap follows the upload setting; null is no cap at all.
+ const mib = 1024 * 1024;
+ assert.equal(
+ audioFileProblem({ size: 300 * mib, type: "audio/wav" }, 500 * mib),
+ null,
+ );
+ assert.equal(
+ audioFileProblem({ size: 500 * mib + 1, type: "audio/wav" }, 500 * mib),
+ "Audio is too large. Keep it under 500 MB.",
+ );
+ assert.equal(
+ audioFileProblem({ size: 10 * 1024 * mib, type: "audio/wav" }, null),
+ null,
+ );
+ assert.equal(
+ audioFileProblem({ size: 0, type: "audio/wav" }, null),
+ "This file is empty.",
+ );
+ assert.match(hook, /await loadUploadLimitSettings\(\)/);
+ assert.match(hook, /audioFileProblem\(\s*\{[^}]*\},\s*maxBytes,\s*\)/);
assert.match(
audioFileProblem({ size: 10, type: "image/png", name: "a.png" }) ?? "",
/not an audio file/,
diff --git a/studio/frontend/tests/audio-transcribe-rail.test.ts b/studio/frontend/tests/audio-transcribe-rail.test.ts
index c1cbfc7c39f..88bbb210899 100644
--- a/studio/frontend/tests/audio-transcribe-rail.test.ts
+++ b/studio/frontend/tests/audio-transcribe-rail.test.ts
@@ -18,6 +18,7 @@ test("the rail takes audio through the shared input card, worded for Transcribe
rail,
/<AudioHistoryProvider value=\{historyClips\}>\s*<div data-tour="audio-record">\s*<AudioSourceInput[\s\S]*?maxRecordSeconds=\{RECORDING_MAX_SECONDS\}\s*expiredMessage="This upload expired\. Add it again\."\s*usesFirstSeconds=\{null\}\s*recordHint="Record up to 30 minutes, then transcribe it\."/,
);
+ assert.match(rail, /label="Audio"\s*hint=\{switches\.sourceHint\}/);
});
test("both switches come from the model's capabilities, an always-on one reads as a fact", () => {
diff --git a/studio/frontend/tests/transcribe-capabilities.test.ts b/studio/frontend/tests/transcribe-capabilities.test.ts
index 49f2d11bfc5..4deed3fe9d2 100644
--- a/studio/frontend/tests/transcribe-capabilities.test.ts
+++ b/studio/frontend/tests/transcribe-capabilities.test.ts
@@ -9,6 +9,7 @@ import {
type TranscribeSwitch,
connectionTranscribeModels,
connectionTranscribeSwitches,
+ transcribeSourceHint,
transcribeSwitches,
} from "../src/features/audio/transcribe-capabilities.ts";
import {
@@ -212,3 +213,31 @@ test("a connection's Voxtral TTS model stays out of Transcribe; its realtime ASR
"voxtral-mini-transcribe-realtime",
]);
});
+
+test("the source hint names how long this model's audio can run", () => {
+ assert.equal(
+ transcribeSourceHint(4 * 3600),
+ "Up to 4 hours with this model. Drop a file, record, or reuse a clip.",
+ );
+ assert.equal(
+ transcribeSourceHint(30 * 60),
+ "Up to 30 minutes with this model. Drop a file, record, or reuse a clip.",
+ );
+ assert.equal(
+ transcribeSourceHint(90 * 60),
+ "Up to 90 minutes with this model. Drop a file, record, or reuse a clip.",
+ );
+ const today = "Up to 30 minutes. Drop a file, record, or reuse a clip.";
+ assert.equal(transcribeSourceHint(null), today);
+ assert.equal(transcribeSourceHint(), today);
+ assert.equal(
+ switches({ max_seconds: 14400 }).sourceHint,
+ transcribeSourceHint(14400),
+ );
+ assert.equal(switches({}).sourceHint, today);
+ assert.equal(switches(null).sourceHint, today);
+ assert.equal(
+ connectionTranscribeSwitches({ timestamps: true }, "whisper-1").sourceHint,
+ today,
+ );
+});