From 8b4c0be34bd058ce61dd0c7bec4d1c922adf7d6b Mon Sep 17 00:00:00 2001 From: ThioJoe <12518330+ThioJoe@users.noreply.github.com> Date: Sun, 28 Jan 2024 17:22:32 -0700 Subject: [PATCH] Add check for too-long audio clips Will check while adding audio clips to final audio file whether any are too long such that they will overrun into the next audio clip. Or if its the last clip, then if it will be cut off at the end. --- Scripts/audio_builder.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Scripts/audio_builder.py b/Scripts/audio_builder.py index 6745d3b..fdbeac6 100644 --- a/Scripts/audio_builder.py +++ b/Scripts/audio_builder.py @@ -203,6 +203,17 @@ def build_audio(subsDict, langDict, totalAudioLength, twoPassVoiceSynth=False): virtualTrimmedFileDict[key].seek(0) # Not 100% sure if this is necessary but it was in the other place it is used canvas = insert_audio(canvas, stretchedClip, value['start_ms']) + + # Print warning if audio clip is longer than expected and would overlap next clip + currentClipExpectedDuration = int(value['duration_ms']) + currentClipTrueDuration = stretchedClip.duration_seconds * 1000 + difference = str(round(currentClipTrueDuration - currentClipExpectedDuration)) + if key < len(subsDict) and (currentClipTrueDuration + int(value['start_ms']) > int(subsDict[key+1]['start_ms'])): + print(f"WARNING: Audio clip {str(key)} for language {langDict['languageCode']} is {difference}ms longer than expected and may overlap the next clip. Inspect the audio file after completion.") + elif key == len(subsDict) and (currentClipTrueDuration + int(value['start_ms']) > totalAudioLength): + print(f"WARNING: Audio clip {str(key)} for language {langDict['languageCode']} is {difference}ms longer than expected and may cut off at the end of the file. Inspect the audio file after completion.") + + keyIndex = list(subsDict.keys()).index(key) print(f" Final Audio Processed: {keyIndex+1} of {len(subsDict)}", end="\r") print("\n")