Spaces:
Running
Running
File size: 2,118 Bytes
3d4392e 0d218b1 3d4392e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
"use server"
import { ClapProject, newSegment } from "@aitube/clap"
import { LatentScenes } from "./types"
let defaultSegmentDurationInMs = 2000
/**
* This generates a fully valid Clap blob (compressed archive)
*
* @param param0
* @returns
*/
export async function addLatentScenesToClap({
scenes = [],
clap,
debug = false
}: {
scenes?: LatentScenes
clap: ClapProject
debug?: boolean
}): Promise<ClapProject> {
if (!Array.isArray(scenes) || !scenes?.length) {
return clap
}
let startTimeInMs = 0
let endTimeInMs = defaultSegmentDurationInMs
clap.segments.push(newSegment({
track: 0,
startTimeInMs,
endTimeInMs,
category: "interface",
prompt: "<BUILTIN:DISCLAIMER>",
label: "fish",
outputType: "interface",
}))
for (const { characters, locations, actions } of scenes) {
startTimeInMs = endTimeInMs
endTimeInMs = startTimeInMs + defaultSegmentDurationInMs
let track = 0
for (const character of characters) {
clap.segments.push(newSegment({
track: track++,
startTimeInMs,
endTimeInMs,
category: "characters",
prompt: character,
label: character,
outputType: "text",
}))
}
for (const location of locations) {
clap.segments.push(newSegment({
track: track++,
startTimeInMs,
endTimeInMs,
category: "location",
prompt: location,
label: location,
outputType: "text",
}))
}
for (const action of actions) {
clap.segments.push(newSegment({
track: track++,
startTimeInMs,
endTimeInMs,
category: "action",
prompt: action,
label: action,
outputType: "text",
}))
}
clap.segments.push(newSegment({
track: track++,
startTimeInMs,
endTimeInMs,
category: "video",
prompt: "video",
label: "video",
outputType: "video",
}))
}
if (debug) {
console.log("latentScenesToClap: unpacked Clap content = ", JSON.stringify(clap, null, 2))
}
return clap
} |