Skip to content

The VS Code of video editing, built for agents.

TypeScript

Enhance audio generation options with optional duration parameter

konstantin-paulusc8583eda7fee
diff --git a/apps/web/src/utils/jsx-generation.ts b/apps/web/src/utils/jsx-generation.ts
index 03a1953c..afceb8a3 100644
--- a/apps/web/src/utils/jsx-generation.ts
+++ b/apps/web/src/utils/jsx-generation.ts
@@ -54,7 +54,7 @@ type ResolvedSpec =
| { type: "image"; model: string; prompt: string; aspectRatio: AspectRatio; seed?: number; refIds: string[] }
| { type: "video"; model: string; prompt: string; aspectRatio: AspectRatio; duration: number; audio: boolean; seed?: number; startFrameId?: string; endFrameId?: string }
| { type: "voice"; model: string; prompt: string; voice: string }
- | { type: "audio"; model: string; prompt: string };
+ | { type: "audio"; model: string; prompt: string; duration?: number };
/**
* In-flight generations per world, keyed by `generationKey`, so identical
@@ -153,6 +153,7 @@ async function resolveSpec(world: EngineWorld, spec: AssetSpecInput, memo: Gener
type: "audio",
model: spec.model ?? PROMPT_INPUT_AUDIO_MODEL_OPTIONS[0].id,
prompt: spec.prompt,
+ duration: spec.duration,
};
}
}
@@ -187,7 +188,6 @@ function requestGeneration(world: EngineWorld, spec: ResolvedSpec) {
? await Promise.all(spec.refIds.map((id) => uploadInput(world, id)))
: undefined;
- console.log("requesting image generation", spec.model, spec.prompt, spec.aspectRatio, spec.seed, images);
return await trpc.generateImage.mutate({
model: spec.model,
prompt: spec.prompt,
@@ -205,7 +205,6 @@ function requestGeneration(world: EngineWorld, spec: ResolvedSpec) {
spec.endFrameId ? uploadInput(world, spec.endFrameId) : undefined,
]);
- console.log("requesting video generation", spec.model, spec.prompt, spec.aspectRatio, spec.duration, spec.audio, spec.seed, startFrame, endFrame);
return await trpc.generateVideo.mutate({
model: spec.model,
prompt: spec.prompt,
@@ -219,7 +218,6 @@ function requestGeneration(world: EngineWorld, spec: ResolvedSpec) {
})();
}
case "voice": {
- console.log("requesting voice generation", spec.model, spec.prompt, spec.voice);
return trpc.textToSpeech.mutate({
model: spec.model,
prompt: spec.prompt,
@@ -227,10 +225,10 @@ function requestGeneration(world: EngineWorld, spec: ResolvedSpec) {
});
}
case "audio": {
- console.log("requesting audio generation", spec.model, spec.prompt);
return trpc.generateSound.mutate({
model: spec.model,
prompt: spec.prompt,
+ duration: spec.duration,
});
}
}
diff --git a/examples/02-genai.tsx b/examples/02-genai.tsx
index f06b9375..27a6b0c6 100644
--- a/examples/02-genai.tsx
+++ b/examples/02-genai.tsx
@@ -51,6 +51,7 @@ const voiceover = generate.voice({
const ambience = generate.audio({
prompt: "distant ocean waves, low wind, calm coastal ambience",
+ duration: 10,
});
export default function GenAi() {
diff --git a/packages/jsx/src/generate.ts b/packages/jsx/src/generate.ts
index 47ba4a35..6b295012 100644
--- a/packages/jsx/src/generate.ts
+++ b/packages/jsx/src/generate.ts
@@ -49,6 +49,7 @@ export type GenerateVoiceOptions = {
export type GenerateAudioOptions = {
prompt: string;
model?: string;
+ duration?: number;
};
export type AssetSpecInput =
@@ -118,6 +119,9 @@ export const generate = {
audio(opts: GenerateAudioOptions): AssetRef {
requirePrompt(opts.prompt, "audio");
+ if (opts.duration !== undefined && (!Number.isFinite(opts.duration) || opts.duration <= 0)) {
+ throw new Error("generate.audio: duration must be a positive number of seconds");
+ }
return new AssetRef({ type: "audio", ...opts });
},
};
diff --git a/reference/jsx/generate.md b/reference/jsx/generate.md
index 5372ae84..b3ad1718 100644
--- a/reference/jsx/generate.md
+++ b/reference/jsx/generate.md
@@ -66,6 +66,7 @@ generate.voice(opts: {
generate.audio(opts: {
prompt: string; // required
model?: string; // default: first model from `dapi models audio`
+ duration?: number; // seconds; default 30 for music, the model's own default for sfx
}): AssetRef;
```