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 os
import glob
import subprocess
import shutil
import sox
shutil.rmtree('clips')
# os.removedirs('clips')
os.mkdir('clips')
db = sqlite3.connect("file:songbook.sqlite?mode=ro", uri=True)
@ -40,29 +39,36 @@ for song, motif, start, duration in db.execute('''
destination = f'clips/{song:04}-{motif:03}.flac'
print (destination)
print(destination)
source_duration = sox.file_info.duration(source)
# trim and fade start
if start / 1000 < 2:
if start < 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
trim_start = start - 2
fade_in = 2
fade_out = 2
# 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
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)
tf = sox.Transformer()
tf.trim(trim_start, trim_end)
tf.fade(fade_in, fade_out, 't')
sox_status = tf.build_file(source, destination, return_output=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(
id int primary key,
name text not null,
name_jp text,
name_jp text not null,
unique(name,name_jp)
);
@ -15,7 +17,7 @@ create table album(
create table artist(
id int primary key,
name text not null,
name_rm text
name_rm text not null
);
create unique index ix_artist_name on artist(

Binary file not shown.

Binary file not shown.