forked from bill317996/SoloLa
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
executable file
·68 lines (59 loc) · 2.72 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
from lib import transcribe
import librosa as rosa
import numpy as np
from guitar_trans.contour import *
# from guitar_trans.technique import *
from guitar_trans.evaluation import evaluation_note, evaluation_esn, evaluation_ts
from os import path, sep, makedirs
# melody components
from melody.melody_extraction import extract_melody
def main(audio_fp, asc_model_fp, desc_model_fp, output_dir, mc_fp=None, eval_note=None, eval_ts=None):
# input/output
audio_fn = path.splitext(path.basename(audio_fp))[0]
save_dir = path.join(output_dir, audio_fn)
print("audio_fp:", audio_fp)
# Setup model
if mc_fp is None:
mc, mc_midi = extract_melody(audio_fp, save_dir)
else:
mc_midi = np.loadtxt(mc_fp)
# Prepare transcribed input
audio, sr = rosa.load(audio_fp, sr=None, mono=True)
melody = Contour(0, mc_midi)
notes = transcribe(audio, melody, asc_model_fp, desc_model_fp, save_dir, audio_fn)
if eval_note is not None:
sg = Song(name=audio_fn)
sg.load_esn_list(eval_note)
evaluation_note(sg.es_note_list, notes, save_dir, audio_fn, string='evaluate notes')
evaluation_esn(sg.es_note_list, notes, save_dir, audio_fn, string='evaluate esn')
if eval_ts is not None:
ans_list = np.loadtxt(eval_ts)
# TODO
def create_parser():
import argparse
p = argparse.ArgumentParser(
formatter_class=argparse.RawDescriptionHelpFormatter,
description=
"""
===================================================================
Script for transcribing a song.
===================================================================
""")
p.add_argument('audio_fp', type=str, metavar='audio_fp',
help='The filepath of the audio to be transcribed.')
p.add_argument('-a', '--asc_model_fp', type=str, metavar='asc_model_fp', default='models/cnn_normmc/ascending.npz',
help='The name of the ascending model.')
p.add_argument('-d', '--desc_model_fp', type=str, metavar='desc_model_fp', default='models/cnn_normmc/descending.npz',
help='The name of the descending model.')
p.add_argument('-o', '--output_dir', type=str, metavar='output_dir', default='outputs',
help='The output directory.')
p.add_argument('-m', '--melody_contour', type=str, default=None,
help='The filepath of melody contour.')
p.add_argument('-e', '--evaluate', type=str, default=None,
help='The filepath of answer file.')
return p
if __name__ == '__main__':
parser = create_parser()
args = parser.parse_args()
main(args.audio_fp, args.asc_model_fp, args.desc_model_fp,
args.output_dir, args.melody_contour, args.evaluate)