uses pysox to script clipmaking

This commit is contained in:
Effie 2023-06-04 12:52:50 +10:00
parent 1ea92d38dd
commit 6a3216a25b
4 changed files with 25 additions and 17 deletions

View File

@ -1,11 +1,10 @@
import sqlite3 import sqlite3
import os import os
import glob import glob
import subprocess
import shutil import shutil
import sox
shutil.rmtree('clips') shutil.rmtree('clips')
# os.removedirs('clips')
os.mkdir('clips') os.mkdir('clips')
db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True) db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True)
@ -42,27 +41,34 @@ for song, motif, start, duration in db.execute('''
print(destination) print(destination)
source_duration = sox.file_info.duration(source)
# trim and fade start # trim and fade start
if start / 1000 < 2: if start < 2:
trim_start = 0 trim_start = 0
trim_duration = duration / 1000 + start / 1000 + 2
fade_in = 0 fade_in = 0
fade_out = 2
else: else:
trim_start = start / 1000 - 2 trim_start = start - 2
trim_duration = duration / 1000 + 4
fade_in = 2 fade_in = 2
fade_out = 2
# trim and fade end (to be continued) # trim and fade end (to be continued)
if source_duration - (start + duration ) < 2:
trim_end = None
fade_out = 0
else:
trim_end = start + duration + 2
fade_out = 2
# call sox # call sox
sox_args = [str(x) for x in ["sox", source, destination, tf = sox.Transformer()
"trim", trim_start, trim_duration, tf.trim(trim_start, trim_end)
"fade", "t", fade_in, "-0", fade_out]] tf.fade(fade_in, fade_out, 't')
print(' '.join(sox_args)) sox_status = tf.build_file(source, destination, return_output=True)
subprocess.run(sox_args, check = True)
# error check
if sox_status != (0, '', ''):
print(sox_status)

6
db.sql
View File

@ -1,7 +1,9 @@
PRAGMA foreign_keys = ON;
create table song( create table song(
id int primary key, id int primary key,
name text not null, name text not null,
name_jp text, name_jp text not null,
unique(name,name_jp) unique(name,name_jp)
); );
@ -15,7 +17,7 @@ create table album(
create table artist( create table artist(
id int primary key, id int primary key,
name text not null, name text not null,
name_rm text name_rm text not null
); );
create unique index ix_artist_name on artist( create unique index ix_artist_name on artist(

Binary file not shown.

Binary file not shown.