From 53f0b71783ebe35729851d8918ea22abeec93ce2 Mon Sep 17 00:00:00 2001 From: Effie Date: Sat, 3 Jun 2023 16:34:22 +1000 Subject: [PATCH] add the fade-in and out to the clips --- build_clips.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/build_clips.py b/build_clips.py index b5d18d8..6c2a66a 100644 --- a/build_clips.py +++ b/build_clips.py @@ -2,8 +2,10 @@ import sqlite3 import os import glob import subprocess +import shutil -os.removedirs('clips') +shutil.rmtree('clips') +# os.removedirs('clips') os.mkdir('clips') db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True) @@ -40,6 +42,27 @@ for song, motif, start, duration in db.execute(''' print (destination) + # trim and fade start + + if start / 1000 < 2: + trim_start = 0 + trim_duration = duration / 1000 + start / 1000 + 2 + fade_in = 0 + fade_out = 2 + else: + trim_start = start / 1000 - 2 + trim_duration = duration / 1000 + 4 + fade_in = 2 + fade_out = 2 + + # trim and fade end (to be continued) + + + # call sox - subprocess.run(["sox", source, destination, "trim", f'{start / 1000}', f'{duration / 1000}'], check = True) \ No newline at end of file + sox_args = [str(x) for x in ["sox", source, destination, + "trim", trim_start, trim_duration, + "fade", "t", fade_in, "-0", fade_out]] + print(' '.join(sox_args)) + subprocess.run(sox_args, check = True) \ No newline at end of file