Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
2
2023-362
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
2023-362
2023-362
Commits
5b0cdb08
Commit
5b0cdb08
authored
Oct 30, 2023
by
Thathsarani R.P.H.S.R
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modified record_analysis.py
parent
a31d1c90
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
40 additions
and
0 deletions
+40
-0
IT20201364/record_analysis.py
IT20201364/record_analysis.py
+40
-0
No files found.
IT20201364/record_analysis.py
0 → 100644
View file @
5b0cdb08
import
sys
import
os
import
sounddevice
as
sd
import
numpy
as
np
import
librosa
import
keras.models
# Load the saved emotion identification model
loaded_model
=
keras
.
models
.
load_model
(
'C:/Users/dell/Desktop/F_Project/Virtual_Assistant/my_model.h5'
)
classLabels
=
(
'Angry'
,
'Fear'
,
'Disgust'
,
'Happy'
,
'Sad'
,
'Surprised'
,
'Neutral'
)
def
record_and_analyze_user_input
(
chatbot
):
duration
=
2.5
# Set the duration of the recording (in seconds)
sample_rate
=
22050
*
2
# Set the sample rate of the recording
# Redirect standard output to a null device
sys
.
stdout
=
open
(
os
.
devnull
,
'w'
)
# Record the live audio
recording
=
sd
.
rec
(
int
(
duration
*
sample_rate
),
samplerate
=
sample_rate
,
channels
=
1
)
sd
.
wait
()
# Wait until the recording is finished
# Restore standard output
sys
.
stdout
=
sys
.
__stdout__
# Preprocess the recorded audio
mfccs
=
librosa
.
feature
.
mfcc
(
y
=
recording
.
flatten
(),
sr
=
sample_rate
,
n_mfcc
=
39
)
input_data
=
mfccs
[
np
.
newaxis
,
...
,
np
.
newaxis
]
# Perform emotion prediction
with
np
.
printoptions
(
suppress
=
True
):
predictions
=
loaded_model
.
predict
(
input_data
)
# Get the predicted label
predicted_label
=
classLabels
[
np
.
argmax
(
predictions
)]
# Store the predicted emotion in the array
chatbot
.
sentiment_analysis
.
append
(
predicted_label
)
return
predicted_label
\ 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