From fd99bc50958468221129ac004e6abcf4282cef45 Mon Sep 17 00:00:00 2001 From: audioshaker Date: Mon, 30 Nov 2026 22:26:19 -0800 Subject: [PATCH] Add model variants to targets, run() and the CLI The API now takes a `variant` on each task target, for accounts it has enabled one for (the diarization previews, preview_a to preview_d). The library sends it from Target(variant=...), run(variant=...) applies it to every model named by id, and `audioshake run --variant NAME` does the same from the command line. TargetResult.variant reads back what ran, and `tasks get` shows it as `model (variant)`. Co-Authored-By: Claude Fable 5.1 --- CHANGELOG.md | 9 ++++++++- README.md | 1 + docs/cli.md | 5 +++-- docs/library.md | 18 +++++++++++------- plugin/.claude-plugin/plugin.json | 2 +- plugin/.codex-plugin/plugin.json | 2 +- plugin/skills/audioshake-cli/SKILL.md | 9 ++++++++- src/audioshake/_run.py | 6 ++++++ src/audioshake/aio.py | 2 ++ src/audioshake/cli/run.py | 13 +++++++++++++ src/audioshake/cli/tasks.py | 11 ++++++++--- src/audioshake/client.py | 5 +++++ src/audioshake/types.py | 8 ++++++++ tests/cli/test_main.py | 19 +++++++++++++++++++ tests/lib/test_run.py | 23 +++++++++++++++++++++++ tests/lib/test_types.py | 18 +++++++++++++++++- tests/test_skill_docs.py | 1 + 17 files changed, 135 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba30ffb..749d268 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,14 @@ public surface may still change between minor releases. ## [Unreleased] -Nothing yet. +### Library +- `Target(variant=...)` and `run(variant=...)` select a named variant of a + model, for accounts the API has enabled one for; sent as `variant` on the + target. `TargetResult.variant` reports the one that ran. + +### CLI +- `audioshake run --variant NAME` passes a model variant; `tasks get` and + `tasks list` show it as `model (variant)`. ## [0.1.0] - 2026-10-27 diff --git a/README.md b/README.md index e7d0e53..f605294 100644 --- a/README.md +++ b/README.md @@ -113,6 +113,7 @@ audioshake run song.wav -m vocals,drums -o stems/ audioshake run ./album -m effects,dialogue,music_fx -f mp3 --residual audioshake run https://example.com/talk.mp3 -m transcription --language en audioshake run panel.wav -m multi_voice --num-speakers 3 +audioshake run meeting.wav -m diarization --variant preview_a # a model variant your account is enabled for audioshake models # what your account can run, with cost and formats audioshake tasks list # recent tasks diff --git a/docs/cli.md b/docs/cli.md index 3cc2d87..56fe6cb 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -60,6 +60,7 @@ that has expired, is a usage error (exit 2) before anything runs. | `--residual` | off | Also return everything each model did not capture | | `--language CODE` | | For models that accept one (transcription, alignment); validated per model | | `--num-speakers N` | | For `multi_voice` | +| `--variant NAME` | | A named variant of a model, for accounts the API has enabled one for (`preview_a`...). Applies to every model in the run; a variant the model does not have, or the account may not use, is rejected by the API before the task is created | | `-c, --concurrency N` | 10 | Sources processed at once. Each source also fetches its outputs in parallel | | `-r, --recursive` | off | Descend into sub-directories | | `--no-download` | off | Leave outputs in the API's storage | @@ -98,7 +99,7 @@ still map to one file name, the later one gets `-2` rather than replacing it. ### Progress In a terminal the run paints a live view. The header says what is running -(models, output formats, language, speakers, residual), how many files run at a +(models, output formats, language, speakers, variant, residual), how many files run at a time when there are several, and where the outputs go. Below it is one row per source, with the stage it is at (uploading with a percentage, the task id once it exists, queued, processing, downloading) and how long it has @@ -216,7 +217,7 @@ Created column. `get` shows the task's status and cost, the asset it was made from as `asset ()` (the id alone when the asset can no longer be read, nothing for a task made from a URL), then one row per model. That asset id is what `run asset:ID` takes to run more models on the same -upload. `download` writes `DIR//.` for every +upload. A model that ran as a variant is shown as `model (variant)`. `download` writes `DIR//.` for every completed model of a finished task, the same layout `run` produces; the task id is the folder name only if the original asset cannot be looked up. `--json` prints raw task objects (`list`, `get`) or the written paths (`download`). diff --git a/docs/library.md b/docs/library.md index dca2390..0337fab 100644 --- a/docs/library.md +++ b/docs/library.md @@ -28,7 +28,7 @@ Both clients are context managers. Call `close()` (or `await close()`) otherwise ```python client.run(source, models, *, output_dir=None, format=None, residual=False, - language=None, num_speakers=None, download=True, + language=None, num_speakers=None, variant=None, download=True, poll_interval=10.0, timeout=3600.0, on_progress=None) -> RunResult ``` @@ -43,11 +43,15 @@ comma list or a sequence, and each model produces those it offers — `"srt,mp3" gives `alignment` its SRT and the stems their MP3, `("json", "srt")` gives `alignment` both files from one billed target — while a model offering none of them keeps its default. A format no selected model offers, or an unsupported -`language`, raises `ValidationError` before upload. `Target` still gives full -per-model control: +`language`, raises `ValidationError` before upload. `variant` names a model +variant the API has enabled for the account (`"preview_a"`, say) and, like +`residual`, applies to every model named by id; the API decides which variants +exist and who may use them, and rejects the task before it is billed otherwise. +`Target` still gives full per-model control: ```python client.run("song.wav", ["vocals", Target("alignment", formats=("srt",), language="en")]) +client.run("meeting.wav", [Target("diarization", formats=("json",), variant="preview_a")]) ``` Files are written to `output_dir` (default: current directory) as @@ -139,11 +143,11 @@ All are frozen dataclasses, and their sequences are tuples. Response types keep the full API object in `.raw`. ```python -Target(model, formats=("wav",), residual=False, language=None, num_speakers=None) +Target(model, formats=("wav",), residual=False, language=None, num_speakers=None, variant=None) Output(name, format, link) TargetResult( - model, status, cost, duration, error, outputs -) # status: pending|processing|completed|failed + model, status, cost, duration, error, outputs, variant +) # status: pending|processing|completed|failed; variant: as the API reports it Task(id, targets, raw) # .done .failed .succeeded .cost .outputs .created_at Asset(id, name, format, link) Model( @@ -212,7 +216,7 @@ Errors raise `AuthError` (an `AudioShakeError`). ```python audioshake.expand_models(["vocals, drums", "bass"]) # ['vocals', 'drums', 'bass'] audioshake.build_targets(models, *, catalog=None, format=None, residual=False, - language=None, num_speakers=None) -> list[Target] + language=None, num_speakers=None, variant=None) -> list[Target] # catalog: the list from models.list(), or a {model_id: Model} mapping audioshake.SPEAKER_COUNT_MODELS ``` diff --git a/plugin/.claude-plugin/plugin.json b/plugin/.claude-plugin/plugin.json index a2e2682..5c8efb9 100644 --- a/plugin/.claude-plugin/plugin.json +++ b/plugin/.claude-plugin/plugin.json @@ -2,7 +2,7 @@ "name": "audioshake-cli", "displayName": "AudioShake CLI", "description": "AudioShake is a platform for state-of-the-art AI source separation, transcription, and content analysis — powering post-production workflows, karaoke, dubbing, speech enhancement, music copyright compliance, improving ASR accuracy, and AI training data preparation — at scale, and in production.", - "version": "0.3.11", + "version": "0.3.12", "author": { "name": "AudioShake" }, "homepage": "https://github.com/audioshake/audioshake-python", "repository": "https://github.com/audioshake/audioshake-python", diff --git a/plugin/.codex-plugin/plugin.json b/plugin/.codex-plugin/plugin.json index f898d53..6a45075 100644 --- a/plugin/.codex-plugin/plugin.json +++ b/plugin/.codex-plugin/plugin.json @@ -1,6 +1,6 @@ { "name": "audioshake-cli", - "version": "0.3.11", + "version": "0.3.12", "description": "Run AudioShake models from Codex with the audioshake CLI and Python library: stem separation, dialogue isolation, speech clean-up, lyric transcription and alignment.", "author": { "name": "AudioShake", "url": "https://www.audioshake.ai" }, "homepage": "https://github.com/audioshake/audioshake-python", diff --git a/plugin/skills/audioshake-cli/SKILL.md b/plugin/skills/audioshake-cli/SKILL.md index ed127f5..ada9b07 100644 --- a/plugin/skills/audioshake-cli/SKILL.md +++ b/plugin/skills/audioshake-cli/SKILL.md @@ -60,6 +60,7 @@ audioshake run https://example.com/talk.mp3 -m transcription --language en audioshake run song.wav -m alignment --language en -f srt # subtitles audioshake run song.wav -m vocals,alignment -f srt,mp3 # per-model formats audioshake run panel.wav -m multi_voice --num-speakers 3 +audioshake run meeting.wav -m diarization --variant preview_a # a model variant the account is enabled for audioshake run asset:ID -m drums,bass # reuse an earlier upload (asset_id from --json); no re-upload ``` @@ -70,6 +71,7 @@ audioshake run asset:ID -m drums,bass # reuse an earlier upload (asset_id fr | `--residual` | Also return everything the models did not capture | | `--language CODE` | For transcription/alignment; validated against the model | | `--num-speakers N` | For `multi_voice` | +| `--variant NAME` | A named model variant (for example `preview_a`) that AudioShake has enabled for the account. Applies to every model in the run, so give it its own run; a variant the model lacks or the account may not use is a 400 from the API before anything is billed | | `-c N` | Concurrent sources (default 10) | | `--no-download` | Leave outputs in the API's storage | | `--timeout SECONDS` | Per-task wait (default 3600); raise it for very long inputs | @@ -180,7 +182,12 @@ itself and logs to the `audioshake` logger. request bodies. Never paste `-vv` output anywhere shared: it includes presigned download URLs. - Global flags (`--json`, `--plain`, `--api-key`, `-v`) go before the subcommand. -- `-m vocals,vocals` is rejected: a model runs once per source. +- `-m vocals,vocals` is rejected: a model runs once per source, so comparing + two variants of one model means two runs (`--variant preview_a`, then + `--variant preview_b`), ideally on the same `asset:ID`. +- Only use `--variant` when the user names one; variants are not listed by + `audioshake models`, and the API's 400 names the model when the account is + not enabled for it. - Model ids use underscores, not hyphens, their word order matters, and they are plural (`vocals`, `drums`, `keys`). `-m multi-voice` exits 2 before the upload with `Did you mean 'multi_voice'?`, and `-m lead-vocal` with diff --git a/src/audioshake/_run.py b/src/audioshake/_run.py index 66618f3..6d4a609 100644 --- a/src/audioshake/_run.py +++ b/src/audioshake/_run.py @@ -99,6 +99,7 @@ def build_targets( residual: bool = False, language: str | None = None, num_speakers: int | None = None, + variant: str | None = None, ) -> list[Target]: """Turn model names into fully specified targets. @@ -123,6 +124,10 @@ def build_targets( residual: Also return everything the models did not capture. language: Applied to models that accept one. num_speakers: Applied to models that accept one (``multi_voice``). + variant: Applied to every model named here, as ``residual`` is; the + API does not say which models have variants, so it is passed + through for the API to judge. Use :class:`Target` to vary it per + model. """ catalog = _catalog_by_id(catalog) if isinstance(models, str | Target): @@ -154,6 +159,7 @@ def build_targets( residual=residual, language=language if _accepts_language(name, model) else None, num_speakers=num_speakers if name in SPEAKER_COUNT_MODELS else None, + variant=variant, ) ) if catalog is not None: diff --git a/src/audioshake/aio.py b/src/audioshake/aio.py index 1dbd7c4..88f9196 100644 --- a/src/audioshake/aio.py +++ b/src/audioshake/aio.py @@ -130,6 +130,7 @@ async def run( residual: bool = False, language: str | None = None, num_speakers: int | None = None, + variant: str | None = None, download: bool = True, poll_interval: float = 10.0, timeout: float = 3600.0, @@ -151,6 +152,7 @@ async def run( residual=residual, language=language, num_speakers=num_speakers, + variant=variant, ) asset: Asset | None = None diff --git a/src/audioshake/cli/run.py b/src/audioshake/cli/run.py index 6959580..288c1f8 100644 --- a/src/audioshake/cli/run.py +++ b/src/audioshake/cli/run.py @@ -94,6 +94,7 @@ class RunOptions: residual: bool = False language: str | None = None num_speakers: int | None = None + variant: str | None = None download: bool = True max_concurrent: int = 10 timeout: float = 3600.0 @@ -366,6 +367,7 @@ def _run_one(self, source: str | Path, node: Node, out_dir: Path) -> RunResult: residual=self.options.residual, language=self.options.language, num_speakers=self.options.num_speakers, + variant=self.options.variant, download=self.options.download, timeout=self.options.timeout, on_progress=lambda event: self._on_event(node, event, tally), @@ -837,6 +839,8 @@ def _subtitle(options: RunOptions, targets: Sequence[Target], source_count: int) parts.append(f"lang {options.language}") if options.num_speakers is not None: parts.append(f"{options.num_speakers} speakers") + if options.variant: + parts.append(f"variant {options.variant}") if options.residual: parts.append("residual") if source_count > 1: @@ -897,6 +901,11 @@ def _count(n: int, noun: str) -> str: type=click.IntRange(min=1), help=f"Speaker count, for {', '.join(SPEAKER_COUNT_MODELS)}", ) +@click.option( + "--variant", + metavar="NAME", + help="Model variant, for accounts the API has enabled one for; applies to every model", +) @click.option( "-c", "--concurrency", @@ -931,6 +940,7 @@ def run( residual: bool, language: str | None, num_speakers: int | None, + variant: str | None, concurrency: int, recursive: bool, no_download: bool, @@ -946,6 +956,7 @@ def run( audioshake run song.wav -m alignment --language en -f srt audioshake run song.wav -m vocals,alignment -f srt,mp3 audioshake run panel.wav -m multi_voice --num-speakers 3 + audioshake run meeting.wav -m diarization --variant preview_a """ model_list = expand_models(model_values) if num_speakers is not None and not any(m in SPEAKER_COUNT_MODELS for m in model_list): @@ -964,6 +975,7 @@ def run( residual=residual, language=language, num_speakers=num_speakers, + variant=variant, download=not no_download, max_concurrent=concurrency, timeout=timeout, @@ -982,6 +994,7 @@ def run( residual=residual, language=language, num_speakers=num_speakers, + variant=variant, ) _log_format_fallbacks(targets, output_format, catalog) tracker = ProgressTracker( diff --git a/src/audioshake/cli/tasks.py b/src/audioshake/cli/tasks.py index b906a28..65b9ba4 100644 --- a/src/audioshake/cli/tasks.py +++ b/src/audioshake/cli/tasks.py @@ -9,7 +9,7 @@ import click from rich.markup import escape -from audioshake import AudioShake, AudioShakeError, Task +from audioshake import AudioShake, AudioShakeError, TargetResult, Task from audioshake._run import source_stem from . import _messages @@ -55,7 +55,7 @@ def list_tasks(settings: Settings, limit: int, since: str | None) -> None: ( task.id, _created_str(task), - ", ".join(t.model for t in task.targets), + ", ".join(_model_label(t) for t in task.targets), _status(task), credits_or_none(task.cost), ) @@ -91,7 +91,7 @@ def get_task(settings: Settings, task_id: str) -> None: ["Model", "Status", "Cost", "Outputs", "Error"], [ ( - t.model, + _model_label(t), t.status, credits_or_none(t.cost), ", ".join(f"{o.name}.{o.format}" for o in t.outputs), @@ -178,6 +178,11 @@ def _source_folder(client: AudioShake, task: Task) -> str: return source_stem(name) if name else task.id +def _model_label(target: TargetResult) -> str: + """The model id, with the variant that ran when the API reports one.""" + return f"{target.model} ({target.variant})" if target.variant else target.model + + def _created_str(task: Task) -> str: created = task.created_at return created.strftime("%Y-%m-%d %H:%M") if created else "" diff --git a/src/audioshake/client.py b/src/audioshake/client.py index 4db5f50..c0b2675 100644 --- a/src/audioshake/client.py +++ b/src/audioshake/client.py @@ -146,6 +146,7 @@ def run( residual: bool = False, language: str | None = None, num_speakers: int | None = None, + variant: str | None = None, download: bool = True, poll_interval: float = 10.0, timeout: float = 3600.0, @@ -172,6 +173,9 @@ def run( residual: Also return everything the models did not capture. language: For models that accept one (transcription, alignment). num_speakers: For models that accept one (multi_voice). + variant: A named variant of a model, applied to every model named + by id. The API decides which variants exist and who may use + them; pass :class:`Target` objects to vary it per model. download: Set False to leave results in the API's storage. poll_interval: Seconds between status checks. timeout: Give up waiting after this many seconds. @@ -197,6 +201,7 @@ def run( residual=residual, language=language, num_speakers=num_speakers, + variant=variant, ) asset: Asset | None = None diff --git a/src/audioshake/types.py b/src/audioshake/types.py index 421dbf4..6902a27 100644 --- a/src/audioshake/types.py +++ b/src/audioshake/types.py @@ -122,6 +122,9 @@ class Target: residual: Also return everything the model did not capture. language: Language code for models that accept one (transcription, alignment). num_speakers: Speaker count for models that accept one (multi_voice). + variant: A named variant of the model, for accounts the API has enabled + it for. Passed through as given; the API rejects a variant the + model does not have or the account may not use. """ model: str @@ -129,6 +132,7 @@ class Target: residual: bool = False language: str | None = None num_speakers: int | None = None + variant: str | None = None def to_api(self) -> dict[str, Any]: """Serialize to the API's target shape (camelCase keys).""" @@ -139,6 +143,8 @@ def to_api(self) -> dict[str, Any]: target["language"] = self.language if self.num_speakers is not None: target["numSpeakers"] = self.num_speakers + if self.variant: + target["variant"] = self.variant return target @@ -170,6 +176,7 @@ class TargetResult: duration: float | None = None error: str | None = None outputs: tuple[Output, ...] = () + variant: str | None = None @property def done(self) -> bool: @@ -192,6 +199,7 @@ def from_api(cls, data: Mapping[str, Any]) -> TargetResult: duration=_as_float(data.get("duration")), error=_error_text(data.get("error")) or _error_text(data.get("message")), outputs=outputs, + variant=_as_optional_str(data.get("variant")), ) diff --git a/tests/cli/test_main.py b/tests/cli/test_main.py index 89c3b18..c34e9cc 100644 --- a/tests/cli/test_main.py +++ b/tests/cli/test_main.py @@ -111,6 +111,8 @@ def test_forwards_every_option(self, fake, tmp_path): "en", "--num-speakers", "2", + "--variant", + "preview_a", "-c", "3", "--timeout", @@ -128,6 +130,7 @@ def test_forwards_every_option(self, fake, tmp_path): assert models == ["effects", "dialogue", "music_fx", "drums"] assert kwargs["format"] == "mp3" and kwargs["residual"] is True assert kwargs["language"] == "en" and kwargs["num_speakers"] == 2 + assert kwargs["variant"] == "preview_a" assert kwargs["timeout"] == 60.0 assert kwargs["output_dir"] == tmp_path / "out" / "song" assert "--num-speakers only applies" in result.stderr @@ -370,6 +373,22 @@ def test_tasks_get_names_the_asset_it_was_made_from(self, api, asset_id, asset_s assert raw_json.get("assetId") == asset_id assert assets.call_count == lookups + def test_tasks_get_shows_the_variant_a_model_ran_as(self, api): + api.get("/tasks/task_1").respond( + 200, + json={ + "id": "task_1", + "targets": [ + {"model": "diarization", "status": "completed", "variant": "preview_a"}, + {"model": "vocals", "status": "completed"}, + ], + }, + ) + result = invoke("tasks", "get", "task_1") + assert result.exit_code == 0, result.stderr + assert "diarization (preview_a)" in result.stdout + assert "vocals (" not in result.stdout + def test_tasks_download_falls_back_to_task_id_without_asset(self, api, tmp_path): raw = _task().raw api.get("/tasks/task_1").respond(200, json=raw) diff --git a/tests/lib/test_run.py b/tests/lib/test_run.py index 7c15dc8..5b43e52 100644 --- a/tests/lib/test_run.py +++ b/tests/lib/test_run.py @@ -159,6 +159,15 @@ def test_explicit_targets_pass_through_and_mix(self): targets = build_targets(["vocals", custom]) assert targets == [Target("vocals"), custom] + def test_a_variant_reaches_every_named_model_but_no_ready_target(self, models_json): + # The API does not say which models have variants, so a variant is not + # filtered by the catalog; a Target keeps whatever its author set. + ready = Target("transcription", formats=("json",)) + targets = build_targets( + ["diarization", "vocals", ready], catalog=_catalog(models_json), variant="preview_a" + ) + assert [t.variant for t in targets] == ["preview_a", "preview_a", None] + @pytest.mark.parametrize( "models", [ @@ -363,6 +372,20 @@ def test_options_reach_the_payload(self, client, api, storage, task_json, models {"model": "transcription", "formats": ["json"], "residual": True, "language": "de"}, ] + def test_a_variant_is_sent_on_the_target(self, client, api, storage, task_json, models_json): + create = _wire(api, storage, task_json, models_json) + client.run( + "https://cdn.test/a.wav", + "diarization", + format="json", + variant="preview_a", + download=False, + ) + sent = json.loads(create.calls.last.request.content) + assert sent["targets"] == [ + {"model": "diarization", "formats": ["json"], "variant": "preview_a"} + ] + def test_catalog_failure_falls_back_to_defaults( self, client, api, storage, task_json, no_sleep ): diff --git a/tests/lib/test_types.py b/tests/lib/test_types.py index 31b4338..da6cc86 100644 --- a/tests/lib/test_types.py +++ b/tests/lib/test_types.py @@ -25,8 +25,12 @@ class TestTarget: Target("transcription", language="en"), {"model": "transcription", "formats": ["wav"], "language": "en"}, ), + ( + Target("diarization", formats=("json",), variant="preview_a"), + {"model": "diarization", "formats": ["json"], "variant": "preview_a"}, + ), ], - ids=["minimal", "options in camelCase", "language only when set"], + ids=["minimal", "options in camelCase", "language only when set", "variant"], ) def test_to_api_sends_only_what_is_set_in_camel_case(self, target, expected): assert target.to_api() == expected @@ -57,6 +61,18 @@ def test_unknown_keys_survive_in_raw(self): class TestTask: + def test_a_target_reports_the_variant_that_ran(self): + task = Task.from_api( + { + "id": "t", + "targets": [ + {"model": "diarization", "status": "completed", "variant": "preview_a"}, + {"model": "vocals", "status": "completed"}, + ], + } + ) + assert [t.variant for t in task.targets] == ["preview_a", None] + def test_parses_completed_task(self): task = Task.from_api(load_fixture("task_completed.json")) assert task.id == "task_0123456789abcdef" diff --git a/tests/test_skill_docs.py b/tests/test_skill_docs.py index e2bec74..e377427 100644 --- a/tests/test_skill_docs.py +++ b/tests/test_skill_docs.py @@ -90,6 +90,7 @@ def test_every_option_is_documented(where, param): "--format", "-c", "--language", + "--variant", }