Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2021-060
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
2021-060
2021-060
Commits
92e7ac9b
Commit
92e7ac9b
authored
Sep 18, 2021
by
Dhananjaya Jayashanka
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
update IT18126884 branch
parent
a5871b71
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
0 additions
and
281 deletions
+0
-281
Filler Words/FillerAPI.py
Filler Words/FillerAPI.py
+0
-17
Filler Words/Train_Neural_Network.py
Filler Words/Train_Neural_Network.py
+0
-65
Filler Words/getFillterWordCount.py
Filler Words/getFillterWordCount.py
+0
-55
Filler Words/get_features.py
Filler Words/get_features.py
+0
-52
Filler Words/neural_network.py
Filler Words/neural_network.py
+0
-91
Filler Words/trained_cnn.h5
Filler Words/trained_cnn.h5
+0
-0
Flow of the sppech/README.md
Flow of the sppech/README.md
+0
-1
No files found.
Filler Words/FillerAPI.py
deleted
100644 → 0
View file @
a5871b71
import
flask
from
flask_cors
import
CORS
,
cross_origin
import
getFillterWordCount
app
=
flask
.
Flask
(
__name__
)
cors
=
CORS
(
app
)
app
.
config
[
'CORS_HEADERS'
]
=
'Content-Type'
app
.
config
[
"DEBUG"
]
=
True
@
app
.
route
(
'/countFillerWords'
,
methods
=
[
'GET'
])
@
cross_origin
()
def
countFillerWords
():
fillterWordCount
=
getFillterWordCount
.
countFillerWords
(
"../temp.wav"
)
return
fillterWordCount
app
.
run
(
port
=
5001
)
Filler Words/Train_Neural_Network.py
deleted
100644 → 0
View file @
a5871b71
import
numpy
as
np
import
scikitplot
from
sklearn.metrics
import
classification_report
from
sklearn.preprocessing
import
LabelEncoder
from
keras.utils
import
to_categorical
from
sklearn.model_selection
import
train_test_split
import
get_features
import
neural_network
from
matplotlib
import
pyplot
import
sys
def
get_numpy_array
(
features_df
):
X
=
np
.
array
(
features_df
.
feature
.
tolist
())
y
=
np
.
array
(
features_df
.
class_label
.
tolist
())
# encode classification labels
le
=
LabelEncoder
()
# one hot encoded labels
yy
=
to_categorical
(
le
.
fit_transform
(
y
))
return
X
,
yy
,
le
def
get_train_test
(
X
,
y
):
X_train
,
X_test
,
y_train
,
y_test
=
train_test_split
(
X
,
y
,
test_size
=
0.2
,
random_state
=
42
)
return
X_train
,
X_test
,
y_train
,
y_test
if
__name__
==
"__main__"
:
# extract features
print
(
"Extracting features.."
)
features_df
=
get_features
.
extract_features
()
# convert into numpy array
X
,
y
,
le
=
get_numpy_array
(
features_df
)
# split into training and testing data
X_train
,
X_test
,
y_train
,
y_test
=
get_train_test
(
X
,
y
)
num_labels
=
y
.
shape
[
1
]
X_train
=
np
.
expand_dims
(
X_train
,
axis
=
2
)
X_test
=
np
.
expand_dims
(
X_test
,
axis
=
2
)
# create model architecture
model
=
neural_network
.
create_cnn
(
num_labels
)
# train model
print
(
"Training.."
)
neural_network
.
train
(
model
,
X_train
,
X_test
,
y_train
,
y_test
,
"trained_cnn.h5"
)
# compute test loss and accuracy
test_loss
,
test_accuracy
=
neural_network
.
compute
(
X_test
,
y_test
,
"trained_cnn.h5"
)
print
(
"Test loss"
,
test_loss
)
print
(
"Test accuracy"
,
test_accuracy
)
# predicting using trained model with any test file in dataset
neural_network
.
predict
(
"data/ab/ab.ogg"
,
le
,
"trained_cnn.h5"
)
yhat_valid
=
model
.
predict_classes
(
X_train
)
scikitplot
.
metrics
.
plot_confusion_matrix
(
np
.
argmax
(
y_train
,
axis
=
1
),
yhat_valid
,
figsize
=
(
7
,
7
))
pyplot
.
savefig
(
"confusion_matrix_dcnn.png"
)
print
(
f
'total wrong validation predictions: {np.sum(np.argmax(y_train, axis=1) != yhat_valid)}
\n\n
'
)
print
(
classification_report
(
np
.
argmax
(
y_train
,
axis
=
1
),
yhat_valid
))
Filler Words/getFillterWordCount.py
deleted
100644 → 0
View file @
a5871b71
import
os
from
pydub
import
AudioSegment
from
pydub.silence
import
split_on_silence
from
tensorflow.keras.utils
import
to_categorical
from
sklearn.preprocessing
import
LabelEncoder
import
numpy
as
np
import
get_features
import
neural_network
# countPauses("../content analyzing/temp.wav")
ScoreforUserSilence
=
70
/
100
def
get_numpy_array
(
features_df
):
X
=
np
.
array
(
features_df
.
feature
.
tolist
())
y
=
np
.
array
(
features_df
.
class_label
.
tolist
())
# encode classification labels
le
=
LabelEncoder
()
# one hot encoded labels
yy
=
to_categorical
(
le
.
fit_transform
(
y
))
return
X
,
yy
,
le
features_df
=
get_features
.
extract_features
()
X
,
y
,
le
=
get_numpy_array
(
features_df
)
def
countFillerWords
(
filePath
):
fillerWordCount
=
0
sound
=
AudioSegment
.
from_wav
(
filePath
)
chunks
=
split_on_silence
(
sound
,
min_silence_len
=
200
,
silence_thresh
=
sound
.
dBFS
-
16
,
keep_silence
=
150
)
# Chunk Folder file Path
chunk_folder_name
=
"chunks"
# create folder to store chunks
if
not
os
.
path
.
isdir
(
chunk_folder_name
):
os
.
mkdir
(
chunk_folder_name
)
for
i
,
audio_chunk
in
enumerate
(
chunks
,
start
=
1
):
chunk_file
=
os
.
path
.
join
(
chunk_folder_name
,
f
"chunk{i}.wav"
)
audio_chunk
.
export
(
chunk_file
,
format
=
"wav"
,
bitrate
=
'192k'
)
prediction
=
neural_network
.
predict
(
chunk_file
,
le
,
"trained_cnn.h5"
)
print
(
prediction
)
if
float
(
prediction
[
"probability"
])
>
0.99
:
fillerWordCount
+=
1
print
(
"****** How many times Filler words in their Speech *****"
)
# print count of silence
print
(
"Filler words: "
,
fillerWordCount
)
return
{
"message"
:
str
(
fillerWordCount
)
+
" : filler word/s found"
,
"score"
:
ScoreforUserSilence
}
# countFillerWords("../audio.wav")
Filler Words/get_features.py
deleted
100644 → 0
View file @
a5871b71
import
os
import
librosa
import
soundfile
as
sf
import
numpy
as
np
import
glob
import
pandas
as
pd
def
get_features
(
file_name
):
print
(
sf
.
available_formats
())
if
file_name
:
X
,
sample_rate
=
sf
.
read
(
file_name
,
dtype
=
'float32'
)
# mfcc (mel-frequency cepstrum)
print
(
"sample rate: "
,
sample_rate
)
monoX
=
[]
for
leftX
in
X
:
if
len
(
X
.
shape
)
==
2
:
monoX
.
append
(
leftX
[
0
])
else
:
monoX
.
append
(
leftX
)
shape
=
np
.
shape
(
monoX
)
padded_array
=
np
.
zeros
((
300000
))
print
(
len
(
monoX
))
if
len
(
monoX
)
>
300000
:
return
[]
padded_array
[:
shape
[
0
]]
=
monoX
mfccs
=
librosa
.
feature
.
mfcc
(
y
=
padded_array
,
sr
=
sample_rate
,
n_mfcc
=
40
)
mfccs_scaled
=
np
.
mean
(
mfccs
.
T
,
axis
=
0
)
return
mfccs_scaled
def
extract_features
():
# path to dataset containing 10 subdirectories of .ogg files
sub_dirs
=
os
.
listdir
(
'/data'
)
sub_dirs
.
sort
()
print
(
sub_dirs
)
features_list
=
[]
for
label
,
sub_dir
in
enumerate
(
sub_dirs
):
for
file_name
in
glob
.
glob
(
os
.
path
.
join
(
'data'
,
sub_dir
,
"*.ogg"
)):
print
(
"Extracting file "
,
file_name
)
try
:
mfccs
=
get_features
(
file_name
)
except
Exception
as
e
:
print
(
e
)
print
(
"Extraction error"
)
continue
features_list
.
append
([
mfccs
,
label
])
features_df
=
pd
.
DataFrame
(
features_list
,
columns
=
[
'feature'
,
'class_label'
])
print
(
features_df
.
head
())
return
features_df
Filler Words/neural_network.py
deleted
100644 → 0
View file @
a5871b71
# Imports
from
keras.models
import
Sequential
from
keras.layers
import
Dense
,
Dropout
,
Activation
,
Flatten
from
keras.layers
import
Conv1D
,
GlobalAveragePooling1D
,
MaxPooling1D
from
keras.models
import
load_model
import
get_features
from
sklearn.preprocessing
import
LabelEncoder
import
numpy
as
np
import
os
def
create_mlp
(
num_labels
):
model
=
Sequential
()
model
.
add
(
Dense
(
256
,
input_shape
=
(
40
,)))
model
.
add
(
Activation
(
'relu'
))
model
.
add
(
Dropout
(
0.5
))
model
.
add
(
Dense
(
256
,
input_shape
=
(
40
,)))
model
.
add
(
Activation
(
'relu'
))
model
.
add
(
Dropout
(
0.5
))
model
.
add
(
Dense
(
num_labels
))
model
.
add
(
Activation
(
'softmax'
))
return
model
def
create_cnn
(
num_labels
):
model
=
Sequential
()
model
.
add
(
Conv1D
(
64
,
3
,
activation
=
'relu'
,
input_shape
=
(
40
,
1
)))
model
.
add
(
Conv1D
(
64
,
3
,
activation
=
'relu'
))
model
.
add
(
MaxPooling1D
(
3
))
model
.
add
(
Conv1D
(
128
,
3
,
activation
=
'relu'
))
model
.
add
(
Conv1D
(
128
,
3
,
activation
=
'relu'
))
model
.
add
(
GlobalAveragePooling1D
())
model
.
add
(
Dropout
(
0.5
))
model
.
add
(
Dense
(
num_labels
))
model
.
add
(
Activation
(
'softmax'
))
return
model
def
train
(
model
,
X_train
,
X_test
,
y_train
,
y_test
,
model_file
):
# compile the model
model
.
compile
(
loss
=
'categorical_crossentropy'
,
metrics
=
[
'accuracy'
],
optimizer
=
'adam'
)
print
(
model
.
summary
())
print
(
"training for 100 epochs with batch size 32"
)
model
.
fit
(
X_train
,
y_train
,
batch_size
=
10
,
epochs
=
100
,
validation_data
=
(
X_test
,
y_test
))
# save model to disk
print
(
"Saving model to disk"
)
model
.
save
(
model_file
)
def
compute
(
X_test
,
y_test
,
model_file
):
# load model from disk
loaded_model
=
load_model
(
model_file
)
score
=
loaded_model
.
evaluate
(
X_test
,
y_test
)
return
score
[
0
],
score
[
1
]
*
100
def
predict
(
filename
,
le
,
model_file
):
model
=
load_model
(
model_file
)
prediction_feature
=
get_features
.
get_features
(
filename
)
if
len
(
prediction_feature
)
==
0
:
return
{
"pred"
:
""
,
"probability"
:
str
(
0
)}
if
model_file
==
"trained_mlp.h5"
:
prediction_feature
=
np
.
array
([
prediction_feature
])
elif
model_file
==
"trained_cnn.h5"
:
prediction_feature
=
np
.
expand_dims
(
np
.
array
([
prediction_feature
]),
axis
=
2
)
predicted_vector
=
model
.
predict_classes
(
prediction_feature
)
predicted_class
=
le
.
inverse_transform
(
predicted_vector
)
sub_dirs
=
os
.
listdir
(
'data'
)
sub_dirs
.
sort
()
print
(
"Predicted class"
,
sub_dirs
[
predicted_class
[
0
]])
predicted_proba_vector
=
model
.
predict_proba
([
prediction_feature
])
word
=
""
probability
=
0
predicted_proba
=
predicted_proba_vector
[
0
]
for
i
in
range
(
len
(
predicted_proba
)):
category
=
le
.
inverse_transform
(
np
.
array
([
i
]))
print
(
category
[
0
],
"
\t\t
: "
,
format
(
predicted_proba
[
i
],
'.32f'
)
)
if
(
predicted_proba
[
i
]
>
probability
):
probability
=
predicted_proba
[
i
]
word
=
sub_dirs
[
predicted_class
[
0
]]
print
(
"Selected word: "
,
word
)
return
{
"pred"
:
word
,
"probability"
:
str
(
probability
)}
Filler Words/trained_cnn.h5
deleted
100644 → 0
View file @
a5871b71
File deleted
Flow of the sppech/README.md
deleted
100644 → 0
View file @
a5871b71
read me
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment