-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRaagX.py
More file actions
102 lines (86 loc) · 2.91 KB
/
Copy pathRaagX.py
File metadata and controls
102 lines (86 loc) · 2.91 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# 12/05/2020
from keras.engine.saving import model_from_json
from keras.models import Sequential
from keras.layers import Dense
from scipy.io.wavfile import read
import matplotlib as mpl
from matlab import mlarray
mpl.use('Agg')
import matlab.engine
import numpy as np
import eel
import tensorflow as tf
eel.init('web')
# function to get the user input and return the processed audio file to be sent through the NN
@eel.expose
def process_audio(wav_file):
samples = list(wav_file.values())
# Converting the audio to a 1D numpy array. The audio comes in the type .dict
a = np.empty([2686843, 1])
for i in range(2686843):
a[i] = samples[i]
audio = a
audio = audio[79:]
audio = audio.T
predictions = test_with_sample_model(audio)
raga = generate_raga(predictions)
return raga
def fibonacci_of(n):
if n in {0, 1}: # Base case
return n
return fibonacci_of(n - 1) + fibonacci_of(n - 2) # Recursive case
def generate_fft(audio):
eng = matlab.engine.start_matlab()
# getting the fast fourier transformation of the inserted clip
x = eng.fft(mlarray.double(audio))
ab = eng.abs(x)
ab = np.array(ab)
print(ab)
print(type(ab))
print(np.shape(ab))
# generate_raga(ab)
test_with_fft_model(ab)
def test_with_fft_model(fft):
print(type(fft), np.shape(fft))
json_file = open('model.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
# load weights into new model
loaded_model.load_weights("model.h5")
print("Loaded fft model from disk")
# evaluate loaded model on test data
loaded_model.compile(loss='binary_crossentropy', optimizer='rmsprop', metrics=['accuracy'])
if fft.ndim == 1:
fft = np.array([fft])
predictions1 = loaded_model.predict(fft)
print(predictions1)
def test_with_sample_model(audio_samples):
json_file = open('model2.json', 'r')
loaded_model_json = json_file.read()
json_file.close()
loaded_model = model_from_json(loaded_model_json)
# load weights into new model
loaded_model.load_weights("model2.h5")
print("Loaded sample model from disk")
# evaluate loaded model on test data
loaded_model.compile(loss='binary_crossentropy', optimizer='rmsprop', metrics=['accuracy'])
if audio_samples.ndim == 1:
audio_samples = np.array([audio_samples])
predictions2 = loaded_model.predict(audio_samples)
print(predictions2)
return predictions2
# generate_raga(predictions2)
def generate_raga(predictions):
if predictions[0][0] > 0.5:
raga = "Raaga Yemen"
elif predictions[0][1] > 0.5:
raga = "Raaga Basant"
elif predictions[0][2] > 0.5:
raga = "Raaga Jog"
elif predictions[0][3] > 0.5:
raga = "Raaga Thilakkamod"
else:
raga = "None of the Raagas"
return raga
eel.start('index.html', size=(1000, 600))