Downloads · 30 days
0
dmdoy/Emotion_Recognition_From_Speech
Emotion_Recognition_From_Speech is a audio classification model from dmdoy. Use it for the audio classification task on the model card, and read the license before you ship it in a product. The card lists the license as gpl-3.0.
<p align="justify"The understanding of emotions from voice by a human brain are normal instincts of human beings, but automating the process of emotion recognition from speech without referring any language or linguis…
Downloads · 30 days
0
Access
Public
Updated Mar 19, 2024
Repo size
162 MB
Likes
3
Public
Click a slice to open those files.
.csv134 MB · 82%
From the Hugging Face model README

<a href="http://ffmpeg.org/"><img src="https://img.shields.io/badge/ffmpeg-green?style=flat&logo=ffmpeg&labelColor=green"></a>
<a href="https://pandas.pydata.org/"><img src="https://img.shields.io/badge/pandas-darkblue?style=flat&logo=pandas&labelColor=darkblue"></a>
<a href="https://numpy.org/"><img src="https://img.shields.io/badge/numpy-skyblue?style=flat&logo=numpy&labelColor=skyblue"></a>
<a href="https://www.tensorflow.org/"><img src="https://img.shields.io/badge/tensorflow-orange?style=flat&logo=tensorflow&labelColor=orange"></a>
<a href="https://docs.python.org/3/library/os.html"><img src="https://img.shields.io/badge/os-lightyellow?style=flat&logo=os&labelColor=lightyellow"></a>
<a href="https://docs.python.org/3/library/time.html"><img src="https://img.shields.io/badge/time-lightgreen?style=flat&logo=time&labelColor=lightgreen"></a>
<a href="https://librosa.org/"><img src="https://img.shields.io/badge/librosa-pink?style=flat&logo=librosa&labelColor=pink"></a>
<a href="https://docs.python.org/3/library/warnings.html"><img src="https://img.shields.io/badge/warnings-lightred?style=flat&logo=warings&labelColor=lightred"></a>
<a href="https://docs.python.org/3/library/base64.html"><img src="https://img.shields.io/badge/base64-lightgrey?style=flat&logo=base64&labelColor=lightgrey"></a>
<a href="https://pypi.org/project/google-colab/"><img src="https://img.shields.io/badge/google-colab-lightorange?style=flat&logo=google-colab&labelColor=lightorange"></a>
<a href="https://docs.python.org/3/library/glob.html"><img src="https://img.shields.io/badge/glob-lightgrey?style=flat&logo=glob&labelColor=lightgrey"></a>
<a href="https://docs.python.org/3/library/re.html"><img src="https://img.shields.io/badge/regex-darkgreen?style=flat&logo=regex&labelColor=darkgreen"></a>
<a href="https://scikit-learn.org/stable/"><img src="https://img.shields.io/badge/scikit-learn-darkorange?style=flat&logo=scikit-learn&labelColor=darkorange"></a>
<a href="https://keras.io/"><img src="https://img.shields.io/badge/keras-darkred?style=flat&logo=keras&labelColor=darkred"></a>
<a href="https://www.scipy.org/"><img src="https://img.shields.io/badge/scipy-violet?style=flat&logo=scipy&labelColor=violet"></a>
<a href="https://docs.python.org/3/library/io.html"><img src="https://img.shields.io/badge/io-grey?style=flat&logo=io&labelColor=grey"></a>
<a href="https://ipython.org/"><img src="https://img.shields.io/badge/ipython-purple?style=flat&logo=ipython&labelColor=purple"></a>
<a href="https://matplotlib.org/"><img src="https://img.shields.io/badge/matplotlib-brown?style=flat&logo=matplotlib&labelColor=brown"></a>
<a href="https://www.python.org/doc/"><img src="https://img.shields.io/badge/python3-yellow?style=flat&logo=python3&labelColor=yellow"></a>
Ryerson Audio Visual Database of Emotional Speech and Song (Ravdess) dataset description:<br> Dataset link to download: "https://www.kaggle.com/uwrfkaggler/ravdess-emotional-speech-audio" <br> Dataset stored on google drive at path: "/content/drive/MyDrive/Audiofiles/audio_speech_actors_01-24/"<br> Dataset contains sub folders and file names as example in numbers format 03-01-01-01-01-01-01.wav.<br> Actor (01 to 24. Odd numbered actors are male, even numbered actors are female).<br> So based on the number there is a identifier for each number and its meaning are as follows:
Crowd sourced Emotional Mutimodal Actors Dataset (CREMA-D) dataset description:<br> Dataset link to download: "https://www.kaggle.com/ejlok1/cremad" <br> Dataset stored on google drive at path: "/content/drive/MyDrive/Audiofiles/AudioWAV/"<br> The format of files is 1001_DFA_ANG_XX.wav, where ANG stands for angry emotion.<br> Similarly different emotion mappings are as follows:<br> {'SAD':'sad','ANG':'angry','DIS':'disgust','FEA':'fear','HAP':'happy','NEU':'neutral'}
Toronto emotional speech set (Tess) dataset description:<br> Dataset link to download: "https://www.kaggle.com/ejlok1/toronto-emotional-speech-set-tess" <br> Dataset stored on google drive at path: "/content/drive/MyDrive/Audiofiles/TESS Toronto emotional speech set data/"<br> There are folders in format OAF_angry, OAF_neural, OAF_disgust, YAF_sad and so on, where name after the underscore of the folder name contains the emotion information, so the name after the underscore of the folder name is taken and files residing insider the folders are labeled accordingly.
Surrey Audio Visual Expressed Emotion (Savee) dataset description:<br> Dataset link to download: "https://www.kaggle.com/ejlok1/surrey-audiovisual-expressed-emotion-savee" <br> Dataset stored on google drive at path: "/content/drive/MyDrive/Audiofiles/ALL/"<br> The files are in a format DC_a01.wav where a single character contains the emotion information , for example character 'a' after underscore in the file name "DC_a01.wav" means emotion is angry.<br> Similarly different emotion mappings are as follows:<br> {'a':'anger','d':'disgust','f':'fear','h':'happiness','n':'neutral','sa':'sadness','su':'surprise'}
def calc_time(func):
def inner(*args, **kwargs):
st = time.time()
result = func(*args,**kwargs)
end = time.time()-st
print("Total time required: {:.3f} ms".format(end * 1000))
return result
return inner



Once the model is build and training is completed the emotion recognition model can be loaded from the path "/content/drive/MyDrive/Audiofiles/emotion-recognition .hdf5" and can be tested for the given input speech in real time.

Below figure shows the training, testing and validation accuracy achieved by the emotion recognition model.

Below figure shows the classification report and it can be seen in the report that for all the classes the value is greater than 0.5 which means the model can predict the emotions accuratly to some extent. If the value is equal to 1.0 for all clases then it means model can predict accurrately always given the input speech. But its diffcult to achieve real time prediction and 100% accuracy on real time envoiurment as there is noise and many other factors which can affect the output. Given a challenge it can overcomed by training with big set of data in different languages to develop a universal model.

The 0,1,2,3,4,5 in classification report resembles to different emotions which can be decoded from below image.

Below figure shows output of confusion matrix.<br>

Below figure shows the training loss and accuracy curves, despite the model giving the training accuracy of 100%, validation and testing accuracy is near to 75%-76%, my model gives the highest accuracy when compared to the authors who previously carried out the research work in this area.

Additionally to check wheather the model can work for all types of voices and on unlabeled data a test was carried out using combination of different voices and unlabled data. Below figure shows the results.

Below figures shows comparison of my model with other authors who worked previously in this area of emotion recognition from speech.

To download and run my google colab file 1130532_ResearchMethodology_Project_Final.ipynb following changes need to be made:
ravdess = "/content/drive/MyDrive/Audiofiles/audio_speech_actors_01-24/"
crema = "/content/drive/MyDrive/Audiofiles/AudioWAV/"
tess = "/content/drive/MyDrive/Audiofiles/TESS Toronto emotional speech set data/"
savee = "/content/drive/MyDrive/Audiofiles/ALL/"
final_combined.to_csv("/content/drive/MyDrive/preprocesseddata.csv",index=False,header=True)
Features.to_csv('/content/drive/MyDrive/Audiofiles/Audio_features_All_pr.csv',index=False)
df = additional_preprocess("/content/drive/MyDrive/Audiofiles/Audio_features_All_pr.csv")
filepath = "/content/drive/MyDrive/Audiofiles/emotion-recognition.hdf5"
res_model = load_model("/content/drive/MyDrive/Audiofiles/emotion-recognition.hdf5")
os.chdir('/content/drive/MyDrive/Audiofiles/realtimetested')
np.save('/content/drive/MyDrive/Audiofiles/realtimetested/audiorec{}.npy'.format(len(files)),audio)
plt.savefig("audiorec{}.png".format(len(files)))
df["path"][i] = '/content/drive/MyDrive/Audiofiles/realtimetested/audiorec{}.npy'.format(len(files))
df.to_csv('/content/drive/MyDrive/Audiofiles/realtimetested/real_time_predicted_audio_features.csv', mode='a', index=False)
model = load_model("/content/drive/MyDrive/Audiofiles/emotion-recognition.hdf5")
path = '/content/drive/MyDrive/Audiofiles/realtimetested/testing on sample voices/'
Features.to_csv('/content/drive/MyDrive/Audiofiles/realtimetested/unkonwaudio.csv',index=False)
df = pd.read_csv('/content/drive/MyDrive/Audiofiles/realtimetested/unkonwaudio.csv')
res_model = load_model("/content/drive/MyDrive/Audiofiles/emotion-recognition.hdf5")
res_model = load_model("/content/drive/MyDrive/Audiofiles/emotion-recognition.hdf5")
os.chdir('/content/drive/MyDrive/Audiofiles/realtimetested')
np.save('/content/drive/MyDrive/Audiofiles/realtimetested/audiorec{}.npy'.format(len(files)),audio)
plt.savefig("audiorec{}.png".format(len(files)))
df["path"][i] = '/content/drive/MyDrive/Audiofiles/realtimetested/audiorec{}.npy'.format(len(files))
df.to_csv('/content/drive/MyDrive/Audiofiles/realtimetested/real_time_predicted_audio_features.csv', mode='a', index=False)
def calc_time(func)
def ravdess_data()
def crema_data()
def tess_data()
def saveee_data()
def fetch_data()
def noise(data)
def stretch(data, rate=0.8)
def shift(data)
def pitch(data, sampling_rate, pitch_factor=0.7)
def extract_features(data,sample_rate)
def get_features(path)
def Audio_features_extract()
def plotgraph(history)
def additional_preprocess(filepath)
def audio_features_final()
def emotion_recognition_model(x_train,y_train,x_val,y_val)
#this javascript is used to tell colab cell to open microphone and record audio
AUDIO_HTML = """
<script>
def get_audio()
def get_features_recorded(data,sr)
def test_realtime(encoder)
def evaluate_model(x_train, x_test, y_train, y_test, x_val, y_val)
@calc_time
def main():
#get train,test data and labels
x_train, x_test, y_train, y_test, x_val, y_val, encoder = audio_features_final()
#call the emotion recognition model
emotion_recognition_model(x_train,y_train,x_val,y_val)
#evaluate the model performance
evaluate_model(x_train, x_test, y_train, y_test, x_val, y_val)
if __name__:main()
x_train, x_test, y_train, y_test, x_val, y_val, encoder = audio_features_final()
test_realtime(encoder)
def unknown_audio()
def diff_lang_test()
'''
Given below are few of my social media accounts where anyone can contact me.<br> <a href="https://in.linkedin.com/in/devansh-mody-5013aaab"><img src="https://img.shields.io/badge/LinkedIn-blue?style=flat&logo=linkedin&labelColor=blue"></a> <a href="https://mobile.twitter.com/modydevansh"><img src="https://img.shields.io/badge/twitter-blue?style=flat&logo=twitter&labelColor=blue"></a> <a href="https://www.youtube.com/channel/UCtc_46TMSXPUMpzVP0IAJUw"><img src="https://img.shields.io/badge/youtube-red?style=flat&logo=youtube&labelColor=red"></a> <a href="https://www.instagram.com/devansh_mody/?hl=en"><img src="https://img.shields.io/badge/instagram-purple?style=flat&logo=instagram&labelColor=pink"></a> <a href="https://devanshmody.blogspot.com/"><img src="https://img.shields.io/badge/My bloging website-yellow?style=flat&logo=blog&labelColor=lightyellow"></a> <br>One can also contact me by email <img src="https://img.shields.io/badge/gmail%20id-devanshmody2017%40gmail.com-red"><br> For access to my google drive to see the setup of the whole project mail me on gmail id mentioned above access will be given to the selected people for some amount of time.
I would like to thank @Ricardo for providing javascript code to inovke mircophone of user from google colab cell. As google colab dosent support audio recording using microphone so a javacript function needs to be written to inovke microphone and record auido. I would also like to thank @Fadi Badine my deep learning neural network model for emotion recognition is based on his model for automatic speech recognition.</p>
[1] Francesc Alı́as, Joan Claudi Socoró and Xavier Sevillano, ”A Review of Physical and Perceptual Feature Extraction Techniques for Speech, Music and Environmental Sounds”, Appl. Sci. 2016.<br> [2] Kannan Venkataramanan and Haresh Rengaraj Rajamohan, ”Emotion Recognition from Speech”, arXiv:1912.10458v1 [cs.SD] 22 Dec 2019.<br> [3] Haiyang Xu, Hui Zhang, Kun Han, Yun Wang, Yiping Peng and Xian-gang Li, ”Learning Alignment for Multimodal Emotion Recognition from Speech”, arXiv:1909.05645v2 [cs.CL] 3 Apr 2020.<br> [4] Aharon Satt, Shai Rozenberg and Ron Hoory, ”Efficient Emotion Recognition from Speech Using Deep Learning on Spectrograms”, INTERSPEECH 2017, Stockholm, Sweden, August 20–24, 2017.<br> [5] Jia Rong, Gang Li and Yi Ping Phoebe Chen, ”Acoustic feature selection for automatic emotion recognition from speech”, Information Processing and Management 45 (2009) 315–328.<br> [6] K. Sreenivasa Rao, Tummala Pavan Kumar, Kusam Anusha, Bathina Leela, Ingilela Bhavana and Singavarapu V.S.K. Gowtham, ”Emotion Recognition from Speech”, (IJCSIT) International Journal of Computer Science and Information Technologies, Vol. 3 (2) , 2012,3603-3607.<br> [7] Vladimir Chernykh and Pavel Prikhodko, ”Emotion Recognition From Speech With Recurrent Neural Networks”, arXiv:1701.08071v2 [cs.CL] 5 Jul 2018.<br> [8] Sabur Ajibola Alim and Nahrul Khair Alang Rashid, ”Some Commonly Speech Feature Feature Extraction Algorithms”. Published: December 12 2018, DOI: 10.5772/intechopen.80419.<br> [9] Oh Wook Kwon, Kwokleung Chan, Jiucang Hao and Te Won Lee, ”Emotion Recognition by Speech Signals”, GENEVA, EUROSPEECH 2003.<br> [10] K.V.Krishna Kishore and P.Krishna Satish, ”Emotion Recognition in Speech Using MFCC and Wavelet Features”, IEEE International Advance Computing Conference (IACC), 2013.<br> [11] Panagiotis Tzirakis, Jiehao Zhang and Björn W. Schuller, ”END-TO-END SPEECH EMOTION RECOGNITION USING DEEP NEURAL NETWORKS”, IEEE International Advance Computing Conference (IACC), 2018.<br>