Skip to content
Extraits de code Groupes Projets
Valider a2f89934 rédigé par Sting's avatar Sting
Parcourir les fichiers

Argument parser + disable onset backtrack

parent e18fbabb
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
import sys import sys
import argparse
import demucs.separate import demucs.separate
import subprocess import subprocess
import shlex import shlex
...@@ -7,33 +8,43 @@ from assUtils import AssWriter ...@@ -7,33 +8,43 @@ from assUtils import AssWriter
from segment import Segment 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) parser = argparse.ArgumentParser(description='AutoKara - Automatic karaoke timing tool')
basename = Path(video_file).stem parser.add_argument("source_file", type=str, help="The video/audio file to time")
audio_file = "media/audio/%s.wav" % basename 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) ass_file = args.ass_file
output_folder = "./media/vocals"
# Not working, don't know why if not args.vocals :
# demucs.separate.main(shlex.split('--two-stems vocals -o "%s" "%s"' % (output_folder, audio_file))) print("Extracting audio from video file...")
subprocess.call(shlex.split('demucs --two-stems vocals -o "%s" "%s"' % (output_folder, audio_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) seg = Segment(vocals_file)
onset_times = seg.onsets() onset_times = seg.onsets()
print("Syls found, writing ASS file...")
writer = AssWriter() writer = AssWriter()
writer.openAss(ass_file) writer.openAss(ass_file)
writer.writeHeader() writer.writeHeader()
......
...@@ -30,6 +30,8 @@ class Segment: ...@@ -30,6 +30,8 @@ class Segment:
onset_bt_times = librosa.frames_to_time(onset_bt, sr=sr) 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_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) # print(onset_bt_rms_times)
''' '''
...@@ -48,7 +50,7 @@ class Segment: ...@@ -48,7 +50,7 @@ class Segment:
plt.show() plt.show()
''' '''
return onset_bt_rms_times return onset_raw_times
if __name__ == "__main__": if __name__ == "__main__":
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter