-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.py
72 lines (61 loc) · 2.88 KB
/
demo.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
69
70
71
72
# =======================================================================================================
# # =====================================================================================================
# # Filename: demo.py
# #
# # Description: This script demonstrates the implemented system by generating a drum track
# #
# # Author: Alexandros Iliadis
# # Project: AIron Drummer
# # Date: July 2022
# # =====================================================================================================
# =======================================================================================================
# Runtime Calculation
import time
start_time = time.time()
print('\n============================================================================================')
print(' Executing file: demo.py ')
print('============================================================================================\n')
# =======================================================================================================
# Import Modules
import os
import sys
sys.path.append(os.path.abspath('Modules'))
from config import *
from midiProcessing import *
from audioProcessing import *
from mido import MidiFile
from keras.models import load_model
# =======================================================================================================
# =======================================================================================================
# Load Model
print('Loading Model ...')
path_name = os.path.abspath('Files')
model_name = 'test_model.h5'
model_path = os.path.join(path_name,model_name)
model = load_model(model_path,compile = False)
# Load MIDI File
print('Loading MIDI File ...')
path_name = os.path.abspath('Files')
midi_name = 'test_midi.mid'
midi_path = os.path.join(path_name,midi_name)
midi = MidiFile(midi_path)
# Load Audio File
print('Loading Audio File ...')
path_name = os.path.abspath('Files')
audio_name = 'test_audio.wav'
audio_path = os.path.join(path_name,audio_name)
audio = loadAudio(audio_path,fs)[0]
# Generate Drum Track
print('Generating Drum Track ...')
drum_track = generateDrumTrack(midi,audio,model,drum_parts,configuration)
# Save Drum Track
print('Saving Drum Track ...')
path_name = os.path.abspath('Files')
midi_path = os.path.join(path_name,'test_drums.mid')
saveDrumTrack(drum_track,midi,midi_path)
# =======================================================================================================
# =======================================================================================================
# Runtime Calculation
print('\n============================================================================================')
print('Runtime: %.3f seconds' % (time.time() - start_time))
print('============================================================================================\n')