shiveshnavin commited on
Commit
c13c990
·
1 Parent(s): 561e4ba

Add contagions seitn

Browse files
common-utils CHANGED
@@ -1 +1 @@
1
- Subproject commit 1ae213fc016e05903e7c41aced495a65fe6cae23
 
1
+ Subproject commit f28bc83d3e2dbd2e43f93d2edcb9a5be5ca97e14
server-plugins/single-static-video.js CHANGED
@@ -77,7 +77,10 @@ export class SingleStaticVideoPlugin extends Plugin {
77
  }
78
  }
79
 
80
- combinedBubbles = await this.combineAllTranscriptBubbles(transcript)
 
 
 
81
  await Promise.all([
82
  this.combineAllAudioCaptions(transcript, combinedAudioCaptionsFilePath),
83
  this.combineAllAudios(transcript, combinedAudioPath)
@@ -166,8 +169,11 @@ export class SingleStaticVideoPlugin extends Plugin {
166
  }
167
  }
168
 
169
- // Takes all transcipts and returns a single array with bubbles from different sections put into a single array and sorted by start time. The bubbles are also adjusted to have the correct start and end times based on the section duration and bubble duration. Return array of bubbles
170
- async combineAllTranscriptBubbles(transcripts) {
 
 
 
171
  let combinedBubbles = [];
172
  let cumulativeOffset = 0;
173
 
@@ -196,6 +202,34 @@ export class SingleStaticVideoPlugin extends Plugin {
196
  // Sort bubbles by their start time
197
  combinedBubbles.sort((a, b) => (a.fromSec || 0) - (b.fromSec || 0));
198
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
199
  this.log(`Combined ${combinedBubbles.length} bubbles from ${transcripts.length} sections`);
200
  return combinedBubbles;
201
  }
 
77
  }
78
  }
79
 
80
+ combinedBubbles = await this.combineAllTranscriptBubbles(transcript, {
81
+ contagious: this.options.contagious || false,
82
+ contagiousDelay: this.options.contagiousDelay ?? 0
83
+ })
84
  await Promise.all([
85
  this.combineAllAudioCaptions(transcript, combinedAudioCaptionsFilePath),
86
  this.combineAllAudios(transcript, combinedAudioPath)
 
169
  }
170
  }
171
 
172
+ // Takes all transcripts and returns a single array with bubbles from different sections put into a single array and sorted by start time. The bubbles are also adjusted to have the correct start and end times based on the section duration and bubble duration. Return array of bubbles.
173
+ // Options:
174
+ // contagious {boolean} - if true, each bubble[N+1].fromSec is forced to bubble[N].toSec + contagiousDelay after sorting
175
+ // contagiousDelay {number} - gap in seconds between consecutive bubbles when contagious=true (default: 0)
176
+ async combineAllTranscriptBubbles(transcripts, { contagious = false, contagiousDelay = 0 } = {}) {
177
  let combinedBubbles = [];
178
  let cumulativeOffset = 0;
179
 
 
202
  // Sort bubbles by their start time
203
  combinedBubbles.sort((a, b) => (a.fromSec || 0) - (b.fromSec || 0));
204
 
205
+ // Apply contagious chaining: bubble[N+1].fromSec = bubble[N].toSec + contagiousDelay
206
+ if (contagious && combinedBubbles.length > 1) {
207
+ this.log(`Applying contagious chaining with delay=${contagiousDelay}s across ${combinedBubbles.length} bubbles.`);
208
+ for (let i = 1; i < combinedBubbles.length; i++) {
209
+ const prev = combinedBubbles[i - 1];
210
+ if (prev.toSec !== undefined && prev.toSec !== null) {
211
+ const newFromSec = prev.toSec + contagiousDelay;
212
+ if (combinedBubbles[i].fromSec !== undefined && combinedBubbles[i].toSec !== undefined) {
213
+ // Preserve original duration, shift the window forward
214
+ const originalDur = combinedBubbles[i].toSec - combinedBubbles[i].fromSec;
215
+ combinedBubbles[i].fromSec = newFromSec;
216
+ combinedBubbles[i].toSec = Math.round((newFromSec + originalDur) * 1000) / 1000;
217
+ } else {
218
+ combinedBubbles[i].fromSec = newFromSec;
219
+ }
220
+ // Mirror into mediaTextPrompts if present
221
+ if (combinedBubbles[i].mediaTextPrompts?.length) {
222
+ combinedBubbles[i].mediaTextPrompts[0].fromSec = combinedBubbles[i].fromSec;
223
+ combinedBubbles[i].mediaTextPrompts[0].toSec = combinedBubbles[i].toSec;
224
+ if (combinedBubbles[i].durationSec !== undefined) {
225
+ combinedBubbles[i].durationSec = Math.round((combinedBubbles[i].toSec - combinedBubbles[i].fromSec) * 1000) / 1000;
226
+ combinedBubbles[i].mediaTextPrompts[0].durationSec = combinedBubbles[i].durationSec;
227
+ }
228
+ }
229
+ }
230
+ }
231
+ }
232
+
233
  this.log(`Combined ${combinedBubbles.length} bubbles from ${transcripts.length} sections`);
234
  return combinedBubbles;
235
  }