From b215b8c93f4574c022b9999076af172c21be3cc7 Mon Sep 17 00:00:00 2001
From: Sting <loic.allegre@ensiie.fr>
Date: Fri, 23 Jun 2023 11:18:10 +0200
Subject: [PATCH] Wrap CNN infer with autokara.py

---
 autokara.py | 7 ++++---
 infer.py    | 9 ++++-----
 2 files changed, 8 insertions(+), 8 deletions(-)

diff --git a/autokara.py b/autokara.py
index 71a77ea..4f672fb 100644
--- a/autokara.py
+++ b/autokara.py
@@ -7,6 +7,7 @@ from pathlib import Path
 from assUtils import AssWriter
 
 from segment import Segment
+import infer
 
 
 parser = argparse.ArgumentParser(description='AutoKara - Automatic karaoke timing tool')
@@ -41,13 +42,13 @@ else:
 
 
 print("Identifying syl starts...")
-seg = Segment(vocals_file)
-onset_times = seg.onsets()
+onsets = infer.segment(sys.argv[1])
+syls = [[t, ''] for t in onsets]
 
 print("Syls found, writing ASS file...")
 writer = AssWriter()
 writer.openAss(ass_file)
 writer.writeHeader()
-writer.writeSyls(onset_times)
+writer.writeSyls(syls)
 writer.closeAss()
 
diff --git a/infer.py b/infer.py
index bc1b6f3..e983b45 100644
--- a/infer.py
+++ b/infer.py
@@ -10,20 +10,19 @@ from librosa.onset import onset_detect
 
 def segment(songfile):
 
+
+    song = Audio(songfile, stereo=False)
+    song.feats = fft_and_melscale(song, include_zero_cross=False)
+
     device = torch.device('cuda:0' if torch.cuda.is_available() else 'cpu')
     net = convNet()
     net = net.to(device)
-
-    with open('./data/pickles/train_data.pickle', mode='rb') as f:
-        songs = pickle.load(f)
-
         
     if torch.cuda.is_available():
         net.load_state_dict(torch.load('./models/model.pth'))
     else:
         net.load_state_dict(torch.load('./models/model.pth', map_location='cpu'))
 
-    song = songs[0]
     inference = net.infer(song.feats, device, minibatch=4192)
     inference = np.reshape(inference, (-1))
 
-- 
GitLab