forked from MrPrajwalB/Speech-Depression-Detection
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e07085e
commit 9af36cf
Showing
14 changed files
with
1,117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,182 @@ | ||
300_P,2 | ||
301_P,3 | ||
302_P,4 | ||
303_P,0 | ||
304_P,6 | ||
305_P,7 | ||
306_P,0 | ||
307_P,4 | ||
308_P,22 | ||
309_P,15 | ||
310_P,4 | ||
311_P,21 | ||
312_P,2 | ||
313_P,7 | ||
314_P,1 | ||
315_P,2 | ||
316_P,6 | ||
317_P,8 | ||
319_P,13 | ||
320_P,11 | ||
322_P,5 | ||
323_P,1 | ||
324_P,5 | ||
325_P,10 | ||
326_P,2 | ||
327_P,4 | ||
328_P,4 | ||
329_P,1 | ||
330_P,12 | ||
331_P,8 | ||
332_P,18 | ||
333_P,5 | ||
334_P,5 | ||
335_P,12 | ||
336_P,7 | ||
337_P,10 | ||
338_P,15 | ||
339_P,11 | ||
340_P,1 | ||
343_P,9 | ||
344_P,11 | ||
345_P,15 | ||
346_P,23 | ||
347_P,16 | ||
348_P,20 | ||
349_P,5 | ||
350_P,11 | ||
351_P,14 | ||
352_P,10 | ||
353_P,11 | ||
354_P,18 | ||
355_P,10 | ||
356_P,10 | ||
357_P,7 | ||
358_P,7 | ||
359_P,13 | ||
360_P,4 | ||
361_P,0 | ||
363_P,0 | ||
364_P,0 | ||
365_P,12 | ||
366_P,0 | ||
367_P,19 | ||
368_P,7 | ||
369_P,0 | ||
370_P,0 | ||
371_P,9 | ||
372_P,13 | ||
373_P,9 | ||
374_P,2 | ||
375_P,5 | ||
376_P,12 | ||
377_P,16 | ||
378_P,1 | ||
379_P,2 | ||
380_P,10 | ||
381_P,16 | ||
382_P,0 | ||
383_P,7 | ||
384_P,15 | ||
385_P,8 | ||
386_P,11 | ||
387_P,2 | ||
388_P,17 | ||
389_P,14 | ||
390_P,9 | ||
391_P,9 | ||
392_P,1 | ||
393_P,2 | ||
395_P,7 | ||
396_P,5 | ||
397_P,5 | ||
399_P,7 | ||
400_P,7 | ||
401_P,9 | ||
402_P,11 | ||
403_P,0 | ||
404_P,0 | ||
405_P,17 | ||
406_P,2 | ||
407_P,3 | ||
408_P,0 | ||
409_P,10 | ||
410_P,12 | ||
411_P,0 | ||
412_P,12 | ||
413_P,10 | ||
414_P,16 | ||
415_P,3 | ||
416_P,3 | ||
417_P,7 | ||
418_P,10 | ||
419_P,3 | ||
420_P,3 | ||
421_P,10 | ||
422_P,12 | ||
423_P,0 | ||
424_P,3 | ||
425_P,6 | ||
426_P,20 | ||
427_P,5 | ||
428_P,0 | ||
429_P,1 | ||
430_P,3 | ||
431_P,2 | ||
432_P,1 | ||
433_P,10 | ||
434_P,2 | ||
435_P,8 | ||
436_P,0 | ||
437_P,0 | ||
438_P,2 | ||
439_P,1 | ||
440_P,19 | ||
441_P,18 | ||
442_P,6 | ||
443_P,1 | ||
444_P,7 | ||
445_P,1 | ||
446_P,0 | ||
447_P,1 | ||
448_P,18 | ||
449_P,2 | ||
450_P,9 | ||
452_P,1 | ||
453_P,17 | ||
454_P,1 | ||
455_P,1 | ||
456_P,6 | ||
457_P,3 | ||
459_P,16 | ||
461_P,17 | ||
462_P,9 | ||
463_P,0 | ||
464_P,0 | ||
465_P,2 | ||
466_P,9 | ||
467_P,0 | ||
468_P,4 | ||
469_P,3 | ||
470_P,3 | ||
471_P,0 | ||
472_P,3 | ||
473_P,0 | ||
474_P,4 | ||
475_P,6 | ||
476_P,3 | ||
477_P,2 | ||
478_P,1 | ||
479_P,7 | ||
481_P,7 | ||
482_P,1 | ||
483_P,15 | ||
484_P,9 | ||
485_P,4 | ||
486_P,2 | ||
487_P,0 | ||
488_P,0 | ||
489_P,3 | ||
490_P,2 | ||
491_P,8 | ||
492_P,0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import numpy as np | ||
import librosa | ||
import matplotlib.pyplot as plt | ||
import os | ||
import glob | ||
|
||
p = [] | ||
q = [] | ||
|
||
path= 'C:\\Users\\Prajwal\\Desktop\\UMD project\\audio_2\\492_P' | ||
|
||
for filename in glob.glob(os.path.join(path, '*.wav')): | ||
dur= librosa.get_duration(filename=filename) | ||
p.append(filename) | ||
q.append(dur) | ||
|
||
final=np.empty([len(p), 2]) | ||
array_name=np.asarray(p) | ||
array_dur=np.asarray(q) | ||
final=np.concatenate((array_name, array_dur)) | ||
plt.hist(array) | ||
plt.xlabel('Duration in seconds') | ||
plt.ylabel('No. of Samples') | ||
plt.title('Speech duration analysis for P_492') | ||
plt.savefig('P_492.jpg') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import pandas as pd | ||
import numpy as np | ||
from sklearn.model_selection import train_test_split | ||
from sklearn.preprocessing import StandardScaler | ||
|
||
l= np.arange(300, 493, 1) | ||
l=np.delete(l, [18, 21, 41, 42, 62, 94, 98, 151, 158, 160, 180]) | ||
|
||
path1=[] | ||
path2=[] | ||
ffeatures=[] | ||
foutput=[] | ||
|
||
outputs=pd.read_csv('/home/prajwal/UMD_FT/PHQ_Patient.csv', sep=',', header=None) | ||
outputs=outputs.iloc[:,1] | ||
output=np.asarray(outputs) | ||
|
||
for i in range(len(l)): | ||
s1= '/home/prajwal/UMD_FT/transcript/' + str(l[i]) + '_TRANSCRIPT.csv' | ||
path1.append(s1) | ||
s2= '/home/prajwal/UMD_FT/wwwdaicwoz/' + str(l[i]) + '_P/' + str(l[i]) +'_COVAREP.csv' | ||
path2.append(s2) | ||
|
||
for j in range(len(path1)): | ||
frames=pd.read_csv(path1[j], sep='\t') | ||
features= pd.read_csv(path2[j], sep= ',', header= None) | ||
frames1=frames[frames['speaker'].str.match('Participant')] | ||
frames2= frames1.iloc[:,0:2] | ||
frames3= frames2.values | ||
frames4= frames3[:,:]*100 | ||
c=[] | ||
for i in range(len(frames4)): | ||
start_frame= int(frames4[i,0]) | ||
stop_frame= int(frames4[i,1]) | ||
a=features.iloc[start_frame:stop_frame, :] | ||
c.append(a) | ||
final_features=pd.concat(c) | ||
ffeatures.append(final_features) | ||
arr_ft=np.full([len(final_features), 1], output[j]) | ||
foutput.append(arr_ft) | ||
|
||
ffeatures=pd.concat(ffeatures) | ||
foutput=np.concatenate(foutput) | ||
foutput1=foutput.astype(int) | ||
|
||
for k in range(len(foutput)): | ||
if(foutput[k][0]>10): | ||
foutput1[k][0]= 1 | ||
else: | ||
foutput1[k][0]= 0 | ||
|
||
ffeatures= StandardScaler().fit_transform(ffeatures) | ||
ffeatures= pd.DataFrame(data=ffeatures) | ||
target1=pd.DataFrame(data=foutput1, columns=['Target']) | ||
finalDf = pd.concat([ffeatures, target1], axis = 1) | ||
|
||
depressed= finalDf[(finalDf['Target']==1)] | ||
control= finalDf[(finalDf['Target']==0)] | ||
|
||
depressed1=depressed.sample(n=10000) | ||
control1= control.sample(n=10000) | ||
finalDF=pd.concat([depressed1,control1], axis=0) | ||
finalDF1=finalDF.drop(['Target'], axis=1) | ||
|
||
X_train, X_test, y_train, y_test = train_test_split(finalDF1, finalDF['Target'], test_size=0.25) | ||
|
||
# Importing the Keras libraries and packages | ||
from keras.models import Sequential | ||
from keras.layers import Dense | ||
|
||
classifier = Sequential() | ||
|
||
# Adding the input layer and the first hidden layer | ||
classifier.add(Dense(units = 8, kernel_initializer = 'uniform', activation = 'relu', input_dim = 74)) | ||
|
||
# Adding the second hidden layer | ||
classifier.add(Dense(units = 16, kernel_initializer = 'uniform', activation = 'relu')) | ||
classifier.add(Dense(units = 32, kernel_initializer = 'uniform', activation = 'relu')) | ||
#classifier.add(Dense(units = 64, kernel_initializer = 'uniform', activation = 'relu')) | ||
#classifier.add(Dense(units = 128, kernel_initializer = 'uniform', activation = 'relu')) | ||
classifier.add(Dense(units = 16, kernel_initializer = 'uniform', activation = 'relu')) | ||
# Adding the output layer | ||
#classifier.add(Dense(units = 32, kernel_initializer = 'uniform', activation = 'relu')) | ||
classifier.add(Dense(units =8, kernel_initializer = 'uniform', activation = 'relu')) | ||
classifier.add(Dense(units = 1, kernel_initializer = 'uniform', activation = 'sigmoid')) | ||
|
||
# Compiling the ANN | ||
classifier.compile(optimizer = 'adam', loss = 'binary_crossentropy', metrics = ['accuracy']) | ||
|
||
# Fitting the ANN to the Training set | ||
classifier.fit(X_train, y_train,validation_data=(X_test,y_test), batch_size =32, epochs =50) | ||
|
||
# Part 3 - Making predictions and evaluating the model | ||
|
||
# Predicting the Test set results | ||
y_pred = classifier.predict(X_test) | ||
from sklearn.metrics import mean_absolute_error | ||
from sklearn.metrics import mean_squared_error | ||
import math | ||
mae=mean_absolute_error(y_test,y_pred) | ||
rmse= math.sqrt(mean_squared_error(y_test, y_pred)) | ||
print(mae) | ||
print(rmse) | ||
|
||
#confusion matrix | ||
y_pred= (y_pred>0.5) | ||
from sklearn.metrics import confusion_matrix | ||
cm = confusion_matrix(y_test, y_pred) | ||
print(cm) | ||
acc= (cm[0][0]+cm[1][1])/(cm[0][0]+cm[0][1]+cm[1][0]+cm[1][1]) | ||
print('The accuracy obtained =', acc) | ||
|
Oops, something went wrong.