Skip to content

Commit 8b4c0be

Browse files
committed
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.
1 parent 2e4a76b commit 8b4c0be

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Scripts/audio_builder.py

+11
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,17 @@ def build_audio(subsDict, langDict, totalAudioLength, twoPassVoiceSynth=False):
203203
virtualTrimmedFileDict[key].seek(0) # Not 100% sure if this is necessary but it was in the other place it is used
204204

205205
canvas = insert_audio(canvas, stretchedClip, value['start_ms'])
206+
207+
# Print warning if audio clip is longer than expected and would overlap next clip
208+
currentClipExpectedDuration = int(value['duration_ms'])
209+
currentClipTrueDuration = stretchedClip.duration_seconds * 1000
210+
difference = str(round(currentClipTrueDuration - currentClipExpectedDuration))
211+
if key < len(subsDict) and (currentClipTrueDuration + int(value['start_ms']) > int(subsDict[key+1]['start_ms'])):
212+
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.")
213+
elif key == len(subsDict) and (currentClipTrueDuration + int(value['start_ms']) > totalAudioLength):
214+
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.")
215+
216+
206217
keyIndex = list(subsDict.keys()).index(key)
207218
print(f" Final Audio Processed: {keyIndex+1} of {len(subsDict)}", end="\r")
208219
print("\n")

0 commit comments

Comments
 (0)