Skip to content

Commit

Permalink
adapt transcript when injecting an intro
Browse files Browse the repository at this point in the history
  • Loading branch information
woolfg committed Jul 8, 2024
1 parent aa9a314 commit 6640df4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions chapters/timestamps.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ function askQuestion(query) {
});
}

function adaptTranscript(path, adStartTime, adEndTime) {
if (adStartTime < 1 || adEndTime < 1) {
function adaptTranscript(path, adStartTime = 0, adEndTime = 0, introDuration = 0) {
if ((adStartTime < 1 || adEndTime < 1) && introDuration < 1) {
return
}
//find transcript file *transcript-slim.json
Expand All @@ -110,12 +110,15 @@ function adaptTranscript(path, adStartTime, adEndTime) {
const transcriptFile = files[0].name
console.log("Found transcript file: " + transcriptFile)
const transcript = JSON.parse(fs.readFileSync(transcriptFile))
const introDurationMs = introDuration * 1000
const start = adStartTime * 1000
const duration = adEndTime * 1000 - start

// move all utterances after the ad to the end of the ad
transcript.utterances.forEach(u => {
if (u.start >= start) {
u.start = u.start + introDurationMs
u.end = u.end + introDurationMs
if (start > 0 && duration > 0 && u.start >= start) {
u.start = u.start + duration
u.end = u.end + duration
}
Expand Down

0 comments on commit 6640df4

Please sign in to comment.