diff --git a/autokara.py b/autokara.py index cf07dfc1c14341c589a253cc5574f77122b8c953..71a77ea574e7ddf251897f2505c7a661c2e15464 100644 --- a/autokara.py +++ b/autokara.py @@ -1,4 +1,5 @@ import sys +import argparse import demucs.separate import subprocess import shlex @@ -7,33 +8,43 @@ from assUtils import AssWriter from segment import Segment -try: - video_file = sys.argv[1] - ass_file = sys.argv[2] -except IndexError: - print("usage : %s video_file" % sys.argv[0]) - sys.exit("Invalid Arguments") -Path("./media/audio").mkdir(parents=True, exist_ok=True) -basename = Path(video_file).stem -audio_file = "media/audio/%s.wav" % basename +parser = argparse.ArgumentParser(description='AutoKara - Automatic karaoke timing tool') +parser.add_argument("source_file", type=str, help="The video/audio file to time") +parser.add_argument("ass_file", type=str, help="The ASS file in which to output the karaoke") +parser.add_argument("--vocals", action="store_true", help="Treat the input as vocals file, i.e. do not perform vocals extraction") -subprocess.call(shlex.split('./extractWav.sh "%s" "%s"' % (video_file, audio_file))) +args = parser.parse_args() -Path("./media/vocals").mkdir(parents=True, exist_ok=True) -output_folder = "./media/vocals" +ass_file = args.ass_file -# Not working, don't know why -# demucs.separate.main(shlex.split('--two-stems vocals -o "%s" "%s"' % (output_folder, audio_file))) -subprocess.call(shlex.split('demucs --two-stems vocals -o "%s" "%s"' % (output_folder, audio_file))) +if not args.vocals : + print("Extracting audio from video file...") + Path("./media/audio").mkdir(parents=True, exist_ok=True) + basename = Path(args.source_file).stem + audio_file = "media/audio/%s.wav" % basename -vocals_file = "./media/vocals/htdemucs/%s/vocals.wav" % basename + subprocess.call(shlex.split('./extractWav.sh "%s" "%s"' % (args.source_file, audio_file))) + Path("./media/vocals").mkdir(parents=True, exist_ok=True) + output_folder = "./media/vocals" + print("Isolating vocals...") + + # Not working, don't know why + # demucs.separate.main(shlex.split('--two-stems vocals -o "%s" "%s"' % (output_folder, audio_file))) + subprocess.call(shlex.split('demucs --two-stems vocals -o "%s" "%s"' % (output_folder, audio_file))) + + vocals_file = "./media/vocals/htdemucs/%s/vocals.wav" % basename +else: + vocals_file = args.source_file + + +print("Identifying syl starts...") seg = Segment(vocals_file) onset_times = seg.onsets() - +print("Syls found, writing ASS file...") writer = AssWriter() writer.openAss(ass_file) writer.writeHeader() diff --git a/segment.py b/segment.py index 91452de420a89b528308d10f8ae351061d388b10..4657a99253c6af66730e4028df6ae78ce3932226 100644 --- a/segment.py +++ b/segment.py @@ -30,6 +30,8 @@ class Segment: onset_bt_times = librosa.frames_to_time(onset_bt, sr=sr) onset_bt_rms_times = librosa.frames_to_time(onset_bt_rms, sr=sr) + onset_raw_times = librosa.frames_to_time(onset_raw, sr=sr) + # print(onset_bt_rms_times) ''' @@ -48,7 +50,7 @@ class Segment: plt.show() ''' - return onset_bt_rms_times + return onset_raw_times if __name__ == "__main__":