Skip to content

Commit

Permalink
New Second page done. #2
Browse files Browse the repository at this point in the history
  • Loading branch information
SharanRajani committed May 30, 2019
2 parents 63fba42 + 94dd51e commit b9a43bc
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 31 deletions.
3 changes: 2 additions & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ def denoise_details():
@app.route('/display_spec')
def display_spec():
filepath = session_filepath
modelpath = "model.hdf5"
with open("./static/wav/temp", "w") as file:
file.write(filepath)
file.close()
mixpath = "./static/wav/temp"
global enhancedpath
enhancedpath = test_gen_spec.predict(mixpath)
enhancedpath = test_gen_spec.predict(modelpath, mixpath)
spec_plot.plotstft(enhancedpath, "./static/images/enhanced_spectogram.png", "jet" )
spec_plot.plotstft(filepath, "./static/images/original_spectogram.png", "jet")
spec_plot.plotstft(enhancedpath, "./static/images/enhanced_spectogram_html.png", "PuBuGn")
Expand Down
1 change: 0 additions & 1 deletion static/wav/temp

This file was deleted.

6 changes: 3 additions & 3 deletions templates/Sixth.html
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,9 @@
}

#bloc10{
/*right: 50%;*/
left: 68%;
top:31%;
right: 6%;
left: 60%;
top:33%;
}

#bloc4{
Expand Down
16 changes: 13 additions & 3 deletions templates/Third.html
Original file line number Diff line number Diff line change
Expand Up @@ -386,10 +386,19 @@
.modal-btn {
flex: 1;
margin: 0;
max-width: 190px;
max-width: 170px;
}
.modal-btn:nth-of-type(1) {
margin-left: -33px;
}
.modal-btn:nth-of-type(2) {
margin-left: 30px;
margin-left: 15px;
width: 250px;
}
.modal-btn:nth-of-type(3) {
margin-left: 15px;
margin-right: -33px;
width: 160px;
}
}

Expand Down Expand Up @@ -443,7 +452,8 @@

<button class="modal-btn u-btn" onclick="location.href='http://127.0.0.1:5000/display_spec'">Back to Spectrograms</button>
<button class="modal-btn u-btn " onclick="location.href='http://127.0.0.1:5000/'">Try another file</button>
<button class="modal-btn u-btn" onclick="location.href='http://127.0.0.1:5000/validate'">Validate Results</button>
<!-- <span style={bgcolor="white"}/>aadfsdgsdgsda</span> -->
<button class="modal-btn u-btn" onclick="location.href='http://127.0.0.1:5000/validate'">Validate Results</button>
</div>
</div>

Expand Down
41 changes: 18 additions & 23 deletions test_gen_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,23 @@
from keras.callbacks import Callback, ModelCheckpoint, EarlyStopping
from keras.utils.io_utils import HDF5Matrix
from scipy import signal
from keras import backend as K
import scipy
import scipy.io
import scipy.io.wavfile as wav
import numpy as np
import h5py
import librosa
import sys
import os

model = load_model("model.hdf5")


print("IM HERE")

def make_spectrum_phase(y, FRAMESIZE, OVERLAP, FFTSIZE):
D=librosa.stft(y,n_fft=FRAMESIZE,hop_length=OVERLAP,win_length=FFTSIZE,window=scipy.signal.hamming)
Sxx = np.log10(abs(D)**2)
Sxx = np.log10(abs(D)**2)
print(str(D) + " the value for D")
phase = np.exp(1j * np.angle(D))
print(str(phase) + " the value of phase")
mean = np.mean(Sxx, axis=1).reshape((257,1))
std = np.std(Sxx, axis=1).reshape((257,1))+1e-12
Sxx = (Sxx-mean)/std
Sxx = (Sxx-mean)/std
return Sxx, phase, mean, std

def recons_spec_phase(Sxx_r, phase):
Expand All @@ -45,20 +39,18 @@ def recons_spec_phase(Sxx_r, phase):



def predict(noisylistpath):
K.clear_session()
model = load_model("model.hdf5")
# model=model #"weights/DNN_spec_20160425v2.hdf5"
FRAMESIZE = 512
OVERLAP = 256
FFTSIZE = 512
RATE = 16000
FRAMEWIDTH = 2
FBIN = FRAMESIZE//2+1
def predict(modelpath, noisylistpath):
model=load_model(modelpath) #"weights/DNN_spec_20160425v2.hdf5"
FRAMESIZE = 512
OVERLAP = 256
FFTSIZE = 512
RATE = 16000
FRAMEWIDTH = 2
FBIN = FRAMESIZE//2+1
# noisylistpath = sys.argv[2]
noisylistpath = noisylistpath
noisylistpath = noisylistpath

with open(noisylistpath, 'r') as f:
with open(noisylistpath, 'r') as f:
for line in f:
print(line)
filename = line.split('/')[-1][:]
Expand All @@ -67,7 +59,7 @@ def predict(noisylistpath):
training_data = np.empty((10000, FBIN, FRAMEWIDTH*2+1)) # For Noisy data

Sxx, phase, mean, std = make_spectrum_phase(y, FRAMESIZE, OVERLAP, FFTSIZE)
idx = 0
idx = 0
for i in range(FRAMEWIDTH, Sxx.shape[1]-FRAMEWIDTH): # 5 Frmae
training_data[idx,:,:] = Sxx[:,i-FRAMEWIDTH:i+FRAMEWIDTH+1] # For Noisy data
idx = idx + 1
Expand All @@ -81,9 +73,12 @@ def predict(noisylistpath):
count+=1
# # The un-enhanced part of spec should be un-normalized
Sxx[:, :FRAMEWIDTH] = (Sxx[:, :FRAMEWIDTH] * std) + mean
Sxx[:, -FRAMEWIDTH:] = (Sxx[:, -FRAMEWIDTH:] * std) + mean
Sxx[:, -FRAMEWIDTH:] = (Sxx[:, -FRAMEWIDTH:] * std) + mean

recons_y = recons_spec_phase(Sxx, phase)
output = librosa.util.fix_length(recons_y, y.shape[0])
wav.write("static/wav/enhanced.wav",RATE,np.int16(output*32767))
return os.path.join("static","wav","enhanced.wav")



0 comments on commit b9a43bc

Please sign in to comment.