Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions docs/guides/cli.md
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,17 @@ opendirector --project PROJECT_UUID canvas add-material --asset ASSET_UUID --x 0

`asset import-url` enables only yt-dlp's site extractors (not the generic extractor), selects only formats downloaded directly over HTTP(S) (videos offered only as HLS/DASH segment streams or as sections return `url_import_unsupported`); inside the download process yt-dlp may start only ffmpeg/ffprobe on local files and deno without network permission, while external downloaders, PhantomJS and other programs are refused, so every network request passes the address check below, refuses playlists and live streams, and limits videos to 15 minutes and 512 MB; when the size is unknown it is counted during the download, which stops once the limit is exceeded. The download runs in a separate process that connects directly, without the system proxy. Every name that process resolves, including redirects and media servers, must resolve only to public addresses; loopback, private, link-local, reserved (including NAT64), multicast and other non-public answers refuse the connection with `url_import_private`. Cancellation, the timeout or the end of the calling process (including a stopped Agent turn) ends the download process and anything it started; on Windows, when the caller itself is killed, the download process exits but an ffmpeg it started may run to completion. The CLI downloads on its own machine and then registers through the same path as `asset import`, so the edit lease is held only for registration, not for the download. The receipt includes `assetId` and the source page (`url`, `title`, `site`, `durationSeconds`). In an Agent turn the file is kept under `downloads/` in the execution directory and reported as `file`; otherwise a temporary directory is used unless `--output-dir` is given. Repeating the same `--operation-id` with the same link returns the original receipt (`replayed: true`) without downloading again; the same `--operation-id` with a different link returns `url_import_operation_conflict`. In an Agent turn the downloaded file in the execution directory is reused. Which sites work depends on yt-dlp's site extractors: some sites block server and data-centre addresses, and sites such as YouTube can additionally need yt-dlp's JavaScript runtime components, which this feature does not install. Such failures return `url_import_failed` with the reason; download the file manually and register it with `asset import`. The canvas **Import video from link** action downloads on the server into an upload handle (one link per handle; another link returns `url_import_handle_conflict`) and then runs the same `asset.import`. Closing the dialog or disconnecting ends the download process and registers nothing.

## Create a speech node / 创建语音节点

```sh
opendirector --project PROJECT_UUID --operation-id OPERATION_UUID audio create-speech \
--model MODEL_CONFIG_UUID --text "一段旁白,两种配乐。" --voice Vivian --x 120 --y 80
```

Choose a configured TTS model. Use a provider voice ID or save one object from the `voices` array returned by `opendirector voice list --model MODEL_CONFIG_UUID` and pass it with `--voice-selection FILE`. Generation rechecks the voice against the provider on submission. Models that support a default voice also accept a call without either option. The receipt contains the editable canvas item and generation spec IDs. Run its `next.command` to submit those revisions. For a retry, reuse the operation ID, the original model selector (UUID or exact name), the other arguments and the contents of any voice record.

选择已配置的 TTS 模型。音色可用服务端 ID,也可将 `opendirector voice list --model MODEL_CONFIG_UUID` 返回的 `voices` 数组中的一个对象保存为文件,并以 `--voice-selection FILE` 指定;提交时会向服务端复核音色。支持默认音色的模型可省略音色选项。创建回执包含可编辑节点和生成配置的 ID;执行其中的 `next.command` 才会提交这两个版本。重试时请沿用原操作 ID、原来填写的模型 UUID 或完整名称及其他参数。使用音色文件时也要保留原记录。

## Voice library

`opendirector voice list --model MODEL_CONFIG_UUID` reads the full library and returns the selected model's connection identity, voices and adapter requirements. For a large MOSS library, request up to 150 voices per page.
Expand Down
84 changes: 82 additions & 2 deletions packages/core/src/opendirector/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
ASSET_DOWNLOAD_ENGLISH, ASSET_REVISION_HEADER, AssetDownloadFile, AssetDownloadReceipt,
)
from opendirector.domain.creation.commands import COMMAND_MODELS, command_fingerprint, parse_command
from opendirector.domain.creation.generation import VoiceSelection
from opendirector.domain.creation.contract_messages import CONTRACT_MESSAGES, contract_message, kebab
from opendirector.domain.projects import ProjectError
from opendirector.domain.timeline_errors import timeline_error, timeline_error_message
Expand All @@ -51,9 +52,14 @@
app = typer.Typer(no_args_is_help=True, help="Start OpenDirector and create or edit projects.",
epilog="Run opendirector COMMAND --help for subcommands and usage. "
"Place --project, --url and other global options before the command.")
def cli_text(english, chinese):
return chinese if os.environ.get("OPENDIRECTOR_LANGUAGE", "en-US").lower().startswith("zh") else english


GROUP_HELP = {
"project": "List, inspect, create, rename, trash or restore projects.",
"model": "Inspect available model configurations and input capabilities.",
"audio": cli_text("Configure editable audio generation nodes in the project.", "配置工程中的可编辑音频生成节点。"),
"voice": "List, create or delete voices on a configured speech service.",
"asset": "Import or download files and manage registered project assets.",
"canvas": "Display, arrange, hide and configure canvas items.",
Expand Down Expand Up @@ -1283,19 +1289,93 @@ def video_create(ctx: typer.Context,
"binding": {"role": "generation", "objectRef": {"id": spec_id}}},
"references": references,
}, identity=operation)
emit_generation_plan(receipt, project_id, operation, spec_id, item_id, "Submit this configured video generation.")


def emit_generation_plan(receipt, project_id, operation, spec_id, item_id, description, route=()):
changed = {item["objectType"]: item for item in receipt["changed"]}
spec_revision = changed["generation_spec"]["revision"]
item_revision = changed["canvas_item"]["revision"]
submit = ["opendirector", "--project", project_id, "--operation-id", str(uuid5(operation, "submit")), "generation", "submit",
submit = ["opendirector", *route, "--project", project_id, "--operation-id", str(uuid5(operation, "submit")), "generation", "submit",
"--spec-id", spec_id, "--expected-spec-revision", str(spec_revision),
"--origin-item-id", item_id,
"--expected-version", f"generation_spec:{spec_id}:{spec_revision}",
"--expected-version", f"canvas_item:{item_id}:{item_revision}"]
emit({**receipt, "specId": spec_id, "itemId": item_id,
"next": {"description": "Submit this configured video generation.",
"next": {"description": description,
"command": shlex.join(submit)}})


@group("audio").command("create-speech", help=cli_text("Create a visible speech node and return its submit command.",
"创建可见的语音节点并返回提交命令。"))
def audio_create_speech(ctx: typer.Context,
model: Annotated[str, typer.Option(help=cli_text("TTS model configuration UUID or unique exact name.", "TTS 模型配置 UUID 或唯一的完整模型名。"))],
text: Annotated[str, typer.Option(help=cli_text("Exact words to speak.", "需要朗读的原文。"))],
x: Annotated[float, typer.Option(help=cli_text("Canvas X coordinate.", "画布 X 坐标。"))],
y: Annotated[float, typer.Option(help=cli_text("Canvas Y coordinate.", "画布 Y 坐标。"))],
voice: Annotated[str | None, typer.Option(help=cli_text("Provider voice ID or name.", "服务端音色 ID 或名称。"))] = None,
voice_selection: Annotated[Path | None, typer.Option(help=cli_text("Saved voice record from this connection.", "当前连接中保存的音色记录文件。"))] = None):
client = ctx.obj
client.command = ctx.command_path
if not text.strip():
raise ProjectError(cli_text("Enter the text to speak.", "请输入需要朗读的文本。"))
parameters = {"creationType": "audio", "mode": "tts"}
selection = None
if voice_selection is not None:
try:
record = read_file(voice_selection)
selection = VoiceSelection.model_validate({k: v for k, v in record.items() if k in VoiceSelection.model_fields})
except (OSError, ValueError) as error:
raise ProjectError(cli_text("Use a voice record from opendirector voice list for this connection.",
"请使用 opendirector voice list 返回的当前连接音色记录。")) from error
if not selection.voiceId.strip():
raise ProjectError(cli_text("The saved voice record needs a voice ID.", "保存的音色记录需要包含音色 ID。"))
if voice is not None and voice != selection.voiceId:
raise ProjectError(cli_text("The voice selection must match --voice.", "音色记录必须与 --voice 一致。"))
voice = selection.voiceId
parameters["voiceSelection"] = selection.model_dump(mode="json", exclude_none=True)
if voice is not None:
if not voice.strip():
raise ProjectError(cli_text("Enter a voice ID or omit --voice.", "请输入音色 ID 或省略 --voice。"))
parameters["voice"] = voice
context = client.call("read_project", {}) if client.live else None
snapshot = context["project"] if context is not None else client.snapshot()
project_id = snapshot["project"]["id"]
operation = client.operation_id or uuid4()
spec_id = str(uuid5(operation, f"speech:{model}"))
item_id = str(uuid5(operation, "item"))
saved = next((s for s in snapshot["generationSpecs"] if s["id"] == spec_id), None)
if saved is not None:
original = saved if saved["revision"] == 1 else client.query("object.get", objectId=spec_id, revision=1)
model_id = original["modelConfigId"]
else:
from opendirector.integrations.model_adapters import capabilities_of

models = context["models"] if context is not None else client.models()
config = select_model([m for m in models if m["kind"] == "audio"], model)
rules = config.get("inputRules") or {}
if "audio.speech" not in capabilities_of(config):
raise ProjectError(cli_text("Select a text-to-speech model. See opendirector model list --kind audio.",
"请选择文本转语音模型。可运行 opendirector model list --kind audio 查看。"))
if selection and selection.connectionId != (rules.get("voiceLibrary") or {}).get("connectionId"):
raise ProjectError(cli_text("Choose a voice from this model connection.", "请选择此模型连接中的音色。"))
model_id = config["id"]
receipt = client.execute("canvas.createGeneration", {
"spec": {"id": spec_id, "projectId": project_id, "kind": "audio", "purpose": "generation",
"modelConfigId": model_id, "prompt": text, "parameters": parameters},
"item": {"id": item_id, "projectId": project_id, "kind": "audio",
"position": {"x": x, "y": y},
"binding": {"role": "generation", "objectRef": {"id": spec_id}}},
}, identity=operation)
route = []
if not client.live:
route.extend(["--url", str(client.http.base_url).rstrip("/")])
if not client.owns_session:
route.extend(["--session", client.session])
description = cli_text("Submit this configured speech generation.", "提交此语音生成配置。")
emit_generation_plan(receipt, project_id, operation, spec_id, item_id, description, route)


@group("job").command("show", help="Read job status once. Use job wait to wait for completion.")
def job_show(ctx: typer.Context, job_id: UUID):
ctx.obj.command = ctx.command_path
Expand Down
Loading
Loading