Commit 30964d7f authored by nivebaby's avatar nivebaby

frontend with django

parent d328cf97
{"nbformat":4,"nbformat_minor":0,"metadata":{"colab":{"name":"Copy of speech recognition full dataset.ipynb","provenance":[{"file_id":"1jjd4YH1MYMRw2sjR4A7Ci9o9C7z5vjQT","timestamp":1650474405271}],"collapsed_sections":[],"mount_file_id":"1b04d6n5eeD17FTYxCWADWP98TlD7qHvE","authorship_tag":"ABX9TyMn9ihRi1oqjgshHDZxKH/D"},"kernelspec":{"name":"python3","display_name":"Python 3"},"language_info":{"name":"python"}},"cells":[{"cell_type":"code","source":["import os\n","Root='/content/drive/MyDrive/speech-emotion-recognition-ravdess-data (2)'\n","os.chdir(Root)\n","\n"],"metadata":{"id":"Z-bwmdG-6Pyf","executionInfo":{"status":"ok","timestamp":1650734992264,"user_tz":-330,"elapsed":8,"user":{"displayName":"Nivethika gnanaseelan","userId":"18142400286402032214"}}},"execution_count":14,"outputs":[]},{"cell_type":"code","source":["from google.colab import drive\n","drive.mount('/content/drive')"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"kLhQ-lGHZT9B","executionInfo":{"status":"ok","timestamp":1650734995434,"user_tz":-330,"elapsed":3176,"user":{"displayName":"Nivethika gnanaseelan","userId":"18142400286402032214"}},"outputId":"70b6d0d8-71ab-4e0c-d758-c83ffb630748"},"execution_count":15,"outputs":[{"output_type":"stream","name":"stdout","text":["Drive already mounted at /content/drive; to attempt to forcibly remount, call drive.mount(\"/content/drive\", force_remount=True).\n"]}]},{"cell_type":"code","source":["ls"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"iDPnmWdW_-sV","executionInfo":{"status":"ok","timestamp":1650734995435,"user_tz":-330,"elapsed":10,"user":{"displayName":"Nivethika gnanaseelan","userId":"18142400286402032214"}},"outputId":"0fa21065-5676-4b9f-a900-90026773ac7e"},"execution_count":16,"outputs":[{"output_type":"stream","name":"stdout","text":["\u001b[0m\u001b[01;34mActor_01\u001b[0m/ \u001b[01;34mActor_08\u001b[0m/ \u001b[01;34mActor_15\u001b[0m/ \u001b[01;34mActor_22\u001b[0m/ \u001b[01;34mActor_29\u001b[0m/ \u001b[01;34mActor_36\u001b[0m/ \u001b[01;34mActor_43\u001b[0m/\n","\u001b[01;34mActor_02\u001b[0m/ \u001b[01;34mActor_09\u001b[0m/ \u001b[01;34mActor_16\u001b[0m/ \u001b[01;34mActor_23\u001b[0m/ \u001b[01;34mActor_30\u001b[0m/ \u001b[01;34mActor_37\u001b[0m/ \u001b[01;34mActor_44\u001b[0m/\n","\u001b[01;34mActor_03\u001b[0m/ \u001b[01;34mActor_10\u001b[0m/ \u001b[01;34mActor_17\u001b[0m/ \u001b[01;34mActor_24\u001b[0m/ \u001b[01;34mActor_31\u001b[0m/ \u001b[01;34mActor_38\u001b[0m/ \u001b[01;34mActor_45\u001b[0m/\n","\u001b[01;34mActor_04\u001b[0m/ \u001b[01;34mActor_11\u001b[0m/ \u001b[01;34mActor_18\u001b[0m/ \u001b[01;34mActor_25\u001b[0m/ \u001b[01;34mActor_32\u001b[0m/ \u001b[01;34mActor_39\u001b[0m/ \u001b[01;34mActor_46\u001b[0m/\n","\u001b[01;34mActor_05\u001b[0m/ \u001b[01;34mActor_12\u001b[0m/ \u001b[01;34mActor_19\u001b[0m/ \u001b[01;34mActor_26\u001b[0m/ \u001b[01;34mActor_33\u001b[0m/ \u001b[01;34mActor_40\u001b[0m/ \u001b[01;34mActor_47\u001b[0m/\n","\u001b[01;34mActor_06\u001b[0m/ \u001b[01;34mActor_13\u001b[0m/ \u001b[01;34mActor_20\u001b[0m/ \u001b[01;34mActor_27\u001b[0m/ \u001b[01;34mActor_34\u001b[0m/ \u001b[01;34mActor_41\u001b[0m/ \u001b[01;34mActor_48\u001b[0m/\n","\u001b[01;34mActor_07\u001b[0m/ \u001b[01;34mActor_14\u001b[0m/ \u001b[01;34mActor_21\u001b[0m/ \u001b[01;34mActor_28\u001b[0m/ \u001b[01;34mActor_35\u001b[0m/ \u001b[01;34mActor_42\u001b[0m/\n"]}]},{"cell_type":"code","source":["pip install pydub"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"WYWLxKmSg96b","executionInfo":{"status":"ok","timestamp":1650735000841,"user_tz":-330,"elapsed":5410,"user":{"displayName":"Nivethika gnanaseelan","userId":"18142400286402032214"}},"outputId":"424952f4-a2d9-464c-e930-89d3907f69dd"},"execution_count":17,"outputs":[{"output_type":"stream","name":"stdout","text":["Requirement already satisfied: pydub in /usr/local/lib/python3.7/dist-packages (0.25.1)\n"]}]},{"cell_type":"code","source":["import librosa\n","import soundfile\n","from pydub import AudioSegment\n","import os,glob,pickle\n","import numpy as np\n","from sklearn.model_selection import train_test_split\n","from sklearn.neural_network import MLPClassifier\n","from sklearn.metrics import accuracy_score"],"metadata":{"id":"4aVYomYIAKqN","executionInfo":{"status":"ok","timestamp":1650734185438,"user_tz":-330,"elapsed":3215,"user":{"displayName":"Nivethika gnanaseelan","userId":"18142400286402032214"}}},"execution_count":5,"outputs":[]},{"cell_type":"code","source":["#Extract features(mfcc,chroma,mel) from a sound file\n","def extract_feature(file_name,mfcc,chroma,mel):\n"," with soundfile.SoundFile(file_name) as sound_file:\n"," X=sound_file.read(dtype='float32')\n"," sample_rate=sound_file.samplerate\n"," if chroma:\n"," stft=np.abs(librosa.stft(X))\n"," result=np.array([])\n"," if mfcc:\n"," mfccs=np.mean(librosa.feature.mfcc(y=X,sr=sample_rate,n_mfcc=40).T,axis=0)\n"," result=np.hstack((result,mfccs))\n"," if chroma:\n"," chroma=np.mean(librosa.feature.chroma_stft(S=stft,sr=sample_rate).T,axis=0)\n"," result=np.hstack((result,chroma))\n"," if mel:\n"," mel=np.mean(librosa.feature.melspectrogram(X,sr=sample_rate).T,axis=0)\n"," resutl=np.hstack((result,mel))\n"," return result\n"],"metadata":{"id":"kFbDJukIDJTi","executionInfo":{"status":"ok","timestamp":1650734185439,"user_tz":-330,"elapsed":5,"user":{"displayName":"Nivethika gnanaseelan","userId":"18142400286402032214"}}},"execution_count":6,"outputs":[]},{"cell_type":"code","source":["#Emotions in the RAVDESS dataset\n","emotions={\n"," '01':'neutral',\n"," '02':'calm',\n"," '03':'happy',\n"," '04':'sad',\n"," '05':'angry',\n"," '06':'fearful',\n"," '07':'disgust',\n"," '08':'suprised'\n","}\n","\n","#Emotions to observe\n","observed_emotions={'calm','happy','fearful','disgust'}"],"metadata":{"id":"UZYxt3PAJ2SP","executionInfo":{"status":"ok","timestamp":1650734185439,"user_tz":-330,"elapsed":5,"user":{"displayName":"Nivethika gnanaseelan","userId":"18142400286402032214"}}},"execution_count":7,"outputs":[]},{"cell_type":"code","source":["#Load the data and extract features for each sound file\n","def load_data(test_size=0.2):\n"," x,y=[],[]\n"," \n"," \n"," for file in glob.glob('/content/drive/MyDrive/speech-emotion-recognition-ravdess-data (2)/Actor*/*.wav'):\n"," file_name=os.path.basename(file)\n"," #converting stereo audio to mono\n"," sound = AudioSegment.from_wav(file)\n"," sound = sound.set_channels(1)\n"," sound.export(file, format=\"wav\")\n"," emotion=emotions[file_name.split(\"-\")[2]]\n"," if emotion not in observed_emotions:\n"," continue\n"," feature=extract_feature(file,mfcc=True,chroma=True,mel=True)\n"," x.append(feature)\n"," y.append(emotion)\n"," return train_test_split(np.array(x),y,test_size= test_size,random_state=9)\n"],"metadata":{"id":"6LV1jldaPCPh","executionInfo":{"status":"ok","timestamp":1650734185440,"user_tz":-330,"elapsed":5,"user":{"displayName":"Nivethika gnanaseelan","userId":"18142400286402032214"}}},"execution_count":8,"outputs":[]},{"cell_type":"code","source":["x_train,x_test,y_train,y_test=load_data(test_size=0.25)\n"],"metadata":{"id":"QoxZQt78RaSo","executionInfo":{"status":"ok","timestamp":1650734982234,"user_tz":-330,"elapsed":294075,"user":{"displayName":"Nivethika gnanaseelan","userId":"18142400286402032214"}}},"execution_count":9,"outputs":[]},{"cell_type":"code","source":["x_train"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"c24LRSccXGWY","executionInfo":{"status":"ok","timestamp":1650734982241,"user_tz":-330,"elapsed":6,"user":{"displayName":"Nivethika gnanaseelan","userId":"18142400286402032214"}},"outputId":"5f6281da-9edd-4e5c-c4ef-6a650481cd12"},"execution_count":10,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([[-5.95626099e+02, 1.15150726e+02, -1.24867172e+01, ...,\n"," 6.23046398e-01, 6.02354646e-01, 6.21970415e-01],\n"," [-5.91970215e+02, 7.29710007e+01, -6.90582132e+00, ...,\n"," 6.48022950e-01, 6.25209510e-01, 5.94240546e-01],\n"," [-5.20889221e+02, 7.05024490e+01, -2.82596359e+01, ...,\n"," 6.47060513e-01, 5.23411751e-01, 4.67101634e-01],\n"," ...,\n"," [-5.49608521e+02, 5.98216209e+01, 3.98647046e+00, ...,\n"," 5.96683025e-01, 6.39297664e-01, 6.79939747e-01],\n"," [-7.00388184e+02, 7.04781189e+01, -2.35088803e-02, ...,\n"," 7.39293993e-01, 7.03237236e-01, 6.44124806e-01],\n"," [-5.21872742e+02, 3.33341560e+01, -2.69798813e+01, ...,\n"," 5.85238993e-01, 6.31202281e-01, 6.67852283e-01]])"]},"metadata":{},"execution_count":10}]},{"cell_type":"code","source":["#Get the number of training and testing datasets\n","print(x_train.shape[0],x_test.shape[0])"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"ELVUwaQpX2Qj","executionInfo":{"status":"ok","timestamp":1650734982241,"user_tz":-330,"elapsed":3,"user":{"displayName":"Nivethika gnanaseelan","userId":"18142400286402032214"}},"outputId":"ddd9060d-932c-40b6-d5eb-2c3501ba0654"},"execution_count":11,"outputs":[{"output_type":"stream","name":"stdout","text":["1152 384\n"]}]},{"cell_type":"code","source":["#Get the number of extracted feature\n","print(f'Features extracted:{x_train.shape[1]}')"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"olUx5ycCYE66","executionInfo":{"status":"ok","timestamp":1650734982242,"user_tz":-330,"elapsed":3,"user":{"displayName":"Nivethika gnanaseelan","userId":"18142400286402032214"}},"outputId":"25c18533-f5cb-49f7-f7ac-904df1597ad1"},"execution_count":12,"outputs":[{"output_type":"stream","name":"stdout","text":["Features extracted:52\n"]}]},{"cell_type":"code","source":["#Intialize the Multi Layer Perceptron classifier\n","model=MLPClassifier(alpha=0.01, batch_size=420, epsilon=1e-08, hidden_layer_sizes=(300,), learning_rate='adaptive', max_iter=500)"],"metadata":{"id":"TT1e1XLPZUhd","executionInfo":{"status":"ok","timestamp":1650734982242,"user_tz":-330,"elapsed":2,"user":{"displayName":"Nivethika gnanaseelan","userId":"18142400286402032214"}}},"execution_count":13,"outputs":[]},{"cell_type":"code","source":["model.fit(x_train,y_train)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"VsmcDwOxf6zb","executionInfo":{"status":"ok","timestamp":1650735030023,"user_tz":-330,"elapsed":15789,"user":{"displayName":"Nivethika gnanaseelan","userId":"18142400286402032214"}},"outputId":"8d9f76a1-7903-4d94-bb7e-bb3fb5634d5a"},"execution_count":18,"outputs":[{"output_type":"execute_result","data":{"text/plain":["MLPClassifier(alpha=0.01, batch_size=420, hidden_layer_sizes=(300,),\n"," learning_rate='adaptive', max_iter=500)"]},"metadata":{},"execution_count":18}]},{"cell_type":"code","source":["#predict for the test set\n","y_pred=model.predict(x_test)"],"metadata":{"id":"kuOZXsRMgJob","executionInfo":{"status":"ok","timestamp":1650735030023,"user_tz":-330,"elapsed":15,"user":{"displayName":"Nivethika gnanaseelan","userId":"18142400286402032214"}}},"execution_count":19,"outputs":[]},{"cell_type":"code","source":["y_pred"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"UzV1EP6lgcij","executionInfo":{"status":"ok","timestamp":1650735030024,"user_tz":-330,"elapsed":14,"user":{"displayName":"Nivethika gnanaseelan","userId":"18142400286402032214"}},"outputId":"f070eac7-58b6-405a-c6cc-826857f35003"},"execution_count":20,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array(['happy', 'fearful', 'happy', 'fearful', 'fearful', 'happy',\n"," 'happy', 'calm', 'disgust', 'happy', 'happy', 'disgust', 'fearful',\n"," 'calm', 'happy', 'calm', 'happy', 'happy', 'happy', 'disgust',\n"," 'calm', 'happy', 'fearful', 'fearful', 'happy', 'calm', 'disgust',\n"," 'calm', 'disgust', 'happy', 'calm', 'disgust', 'happy', 'happy',\n"," 'calm', 'fearful', 'happy', 'disgust', 'fearful', 'disgust',\n"," 'fearful', 'fearful', 'happy', 'fearful', 'fearful', 'disgust',\n"," 'disgust', 'fearful', 'fearful', 'disgust', 'calm', 'disgust',\n"," 'disgust', 'calm', 'calm', 'fearful', 'fearful', 'disgust',\n"," 'disgust', 'disgust', 'calm', 'happy', 'disgust', 'calm', 'happy',\n"," 'fearful', 'happy', 'calm', 'calm', 'calm', 'fearful', 'disgust',\n"," 'happy', 'fearful', 'disgust', 'disgust', 'calm', 'disgust',\n"," 'disgust', 'disgust', 'calm', 'fearful', 'calm', 'fearful',\n"," 'disgust', 'calm', 'disgust', 'disgust', 'calm', 'fearful', 'calm',\n"," 'calm', 'disgust', 'disgust', 'happy', 'happy', 'fearful', 'calm',\n"," 'calm', 'happy', 'fearful', 'calm', 'fearful', 'disgust',\n"," 'disgust', 'calm', 'happy', 'calm', 'disgust', 'fearful',\n"," 'fearful', 'disgust', 'fearful', 'calm', 'disgust', 'calm',\n"," 'fearful', 'disgust', 'disgust', 'calm', 'calm', 'happy', 'happy',\n"," 'fearful', 'happy', 'happy', 'fearful', 'happy', 'happy', 'calm',\n"," 'fearful', 'calm', 'disgust', 'disgust', 'calm', 'fearful',\n"," 'fearful', 'fearful', 'happy', 'happy', 'happy', 'calm', 'fearful',\n"," 'fearful', 'happy', 'disgust', 'fearful', 'happy', 'calm',\n"," 'disgust', 'happy', 'fearful', 'fearful', 'happy', 'fearful',\n"," 'happy', 'calm', 'fearful', 'disgust', 'happy', 'calm', 'happy',\n"," 'fearful', 'fearful', 'calm', 'disgust', 'calm', 'fearful',\n"," 'happy', 'fearful', 'calm', 'calm', 'happy', 'disgust', 'fearful',\n"," 'calm', 'calm', 'happy', 'disgust', 'disgust', 'disgust',\n"," 'disgust', 'happy', 'fearful', 'calm', 'disgust', 'fearful',\n"," 'disgust', 'fearful', 'calm', 'calm', 'happy', 'calm', 'calm',\n"," 'happy', 'happy', 'calm', 'calm', 'happy', 'disgust', 'fearful',\n"," 'fearful', 'happy', 'disgust', 'fearful', 'disgust', 'happy',\n"," 'fearful', 'fearful', 'calm', 'calm', 'happy', 'fearful',\n"," 'disgust', 'disgust', 'fearful', 'fearful', 'calm', 'calm',\n"," 'happy', 'disgust', 'happy', 'fearful', 'happy', 'happy', 'happy',\n"," 'happy', 'fearful', 'disgust', 'happy', 'happy', 'fearful',\n"," 'fearful', 'disgust', 'calm', 'fearful', 'disgust', 'happy',\n"," 'disgust', 'calm', 'disgust', 'disgust', 'happy', 'disgust',\n"," 'fearful', 'happy', 'calm', 'calm', 'calm', 'disgust', 'calm',\n"," 'fearful', 'fearful', 'calm', 'disgust', 'calm', 'calm', 'calm',\n"," 'calm', 'calm', 'calm', 'disgust', 'disgust', 'happy', 'fearful',\n"," 'fearful', 'calm', 'happy', 'fearful', 'fearful', 'happy', 'happy',\n"," 'fearful', 'disgust', 'fearful', 'disgust', 'calm', 'happy',\n"," 'disgust', 'disgust', 'disgust', 'disgust', 'disgust', 'calm',\n"," 'calm', 'calm', 'disgust', 'calm', 'calm', 'calm', 'fearful',\n"," 'happy', 'disgust', 'disgust', 'fearful', 'calm', 'calm', 'calm',\n"," 'fearful', 'disgust', 'disgust', 'calm', 'happy', 'fearful',\n"," 'fearful', 'fearful', 'happy', 'happy', 'calm', 'calm', 'calm',\n"," 'happy', 'disgust', 'fearful', 'disgust', 'calm', 'fearful',\n"," 'disgust', 'disgust', 'disgust', 'fearful', 'disgust', 'happy',\n"," 'disgust', 'disgust', 'happy', 'fearful', 'fearful', 'fearful',\n"," 'calm', 'disgust', 'calm', 'calm', 'calm', 'disgust', 'fearful',\n"," 'disgust', 'calm', 'disgust', 'happy', 'calm', 'calm', 'fearful',\n"," 'calm', 'disgust', 'disgust', 'disgust', 'fearful', 'disgust',\n"," 'happy', 'fearful', 'fearful', 'fearful', 'calm', 'happy', 'happy',\n"," 'fearful', 'disgust', 'calm', 'fearful', 'disgust', 'happy',\n"," 'happy', 'fearful', 'disgust', 'calm', 'fearful', 'happy',\n"," 'disgust', 'disgust', 'fearful', 'calm', 'calm', 'calm', 'fearful',\n"," 'disgust', 'fearful', 'calm', 'disgust', 'fearful', 'happy',\n"," 'happy', 'fearful', 'fearful'], dtype='<U7')"]},"metadata":{},"execution_count":20}]},{"cell_type":"code","source":["#calculate the accuracy of our model\n","accuracy=accuracy_score(y_true=y_test,y_pred=y_pred)\n","\n","print('Accuracy:{:.2f}%'.format(accuracy*100))"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"IX3MbYktggF3","executionInfo":{"status":"ok","timestamp":1650735030024,"user_tz":-330,"elapsed":11,"user":{"displayName":"Nivethika gnanaseelan","userId":"18142400286402032214"}},"outputId":"80e271d0-3116-4f40-87db-74d4619c6f94"},"execution_count":21,"outputs":[{"output_type":"stream","name":"stdout","text":["Accuracy:92.97%\n"]}]},{"cell_type":"code","source":["from sklearn.metrics import accuracy_score,f1_score"],"metadata":{"id":"85r3D59EhRIK","executionInfo":{"status":"ok","timestamp":1650735032632,"user_tz":-330,"elapsed":515,"user":{"displayName":"Nivethika gnanaseelan","userId":"18142400286402032214"}}},"execution_count":22,"outputs":[]},{"cell_type":"code","source":["f1_score(y_test,y_pred,average=None)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"R9dqDRh6hk4t","executionInfo":{"status":"ok","timestamp":1650735035163,"user_tz":-330,"elapsed":411,"user":{"displayName":"Nivethika gnanaseelan","userId":"18142400286402032214"}},"outputId":"f321fe48-5363-4162-8ddf-1d5f2413f918"},"execution_count":23,"outputs":[{"output_type":"execute_result","data":{"text/plain":["array([0.95918367, 0.93467337, 0.92553191, 0.8972973 ])"]},"metadata":{},"execution_count":23}]},{"cell_type":"code","source":["import pandas as pd\n","df=pd.DataFrame({'Actual':y_test,'predicted':y_pred})\n","df.head(20)"],"metadata":{"colab":{"base_uri":"https://localhost:8080/","height":676},"id":"GOfgObJIh3Dj","executionInfo":{"status":"ok","timestamp":1650735037223,"user_tz":-330,"elapsed":803,"user":{"displayName":"Nivethika gnanaseelan","userId":"18142400286402032214"}},"outputId":"5a1c75aa-6aca-41bd-def3-29c8ff88e495"},"execution_count":24,"outputs":[{"output_type":"execute_result","data":{"text/plain":[" Actual predicted\n","0 happy happy\n","1 fearful fearful\n","2 happy happy\n","3 fearful fearful\n","4 fearful fearful\n","5 happy happy\n","6 happy happy\n","7 calm calm\n","8 disgust disgust\n","9 happy happy\n","10 happy happy\n","11 disgust disgust\n","12 fearful fearful\n","13 calm calm\n","14 happy happy\n","15 calm calm\n","16 happy happy\n","17 happy happy\n","18 happy happy\n","19 disgust disgust"],"text/html":["\n"," <div id=\"df-c90c922b-1afc-46c3-b49b-2e62bfc50402\">\n"," <div class=\"colab-df-container\">\n"," <div>\n","<style scoped>\n"," .dataframe tbody tr th:only-of-type {\n"," vertical-align: middle;\n"," }\n","\n"," .dataframe tbody tr th {\n"," vertical-align: top;\n"," }\n","\n"," .dataframe thead th {\n"," text-align: right;\n"," }\n","</style>\n","<table border=\"1\" class=\"dataframe\">\n"," <thead>\n"," <tr style=\"text-align: right;\">\n"," <th></th>\n"," <th>Actual</th>\n"," <th>predicted</th>\n"," </tr>\n"," </thead>\n"," <tbody>\n"," <tr>\n"," <th>0</th>\n"," <td>happy</td>\n"," <td>happy</td>\n"," </tr>\n"," <tr>\n"," <th>1</th>\n"," <td>fearful</td>\n"," <td>fearful</td>\n"," </tr>\n"," <tr>\n"," <th>2</th>\n"," <td>happy</td>\n"," <td>happy</td>\n"," </tr>\n"," <tr>\n"," <th>3</th>\n"," <td>fearful</td>\n"," <td>fearful</td>\n"," </tr>\n"," <tr>\n"," <th>4</th>\n"," <td>fearful</td>\n"," <td>fearful</td>\n"," </tr>\n"," <tr>\n"," <th>5</th>\n"," <td>happy</td>\n"," <td>happy</td>\n"," </tr>\n"," <tr>\n"," <th>6</th>\n"," <td>happy</td>\n"," <td>happy</td>\n"," </tr>\n"," <tr>\n"," <th>7</th>\n"," <td>calm</td>\n"," <td>calm</td>\n"," </tr>\n"," <tr>\n"," <th>8</th>\n"," <td>disgust</td>\n"," <td>disgust</td>\n"," </tr>\n"," <tr>\n"," <th>9</th>\n"," <td>happy</td>\n"," <td>happy</td>\n"," </tr>\n"," <tr>\n"," <th>10</th>\n"," <td>happy</td>\n"," <td>happy</td>\n"," </tr>\n"," <tr>\n"," <th>11</th>\n"," <td>disgust</td>\n"," <td>disgust</td>\n"," </tr>\n"," <tr>\n"," <th>12</th>\n"," <td>fearful</td>\n"," <td>fearful</td>\n"," </tr>\n"," <tr>\n"," <th>13</th>\n"," <td>calm</td>\n"," <td>calm</td>\n"," </tr>\n"," <tr>\n"," <th>14</th>\n"," <td>happy</td>\n"," <td>happy</td>\n"," </tr>\n"," <tr>\n"," <th>15</th>\n"," <td>calm</td>\n"," <td>calm</td>\n"," </tr>\n"," <tr>\n"," <th>16</th>\n"," <td>happy</td>\n"," <td>happy</td>\n"," </tr>\n"," <tr>\n"," <th>17</th>\n"," <td>happy</td>\n"," <td>happy</td>\n"," </tr>\n"," <tr>\n"," <th>18</th>\n"," <td>happy</td>\n"," <td>happy</td>\n"," </tr>\n"," <tr>\n"," <th>19</th>\n"," <td>disgust</td>\n"," <td>disgust</td>\n"," </tr>\n"," </tbody>\n","</table>\n","</div>\n"," <button class=\"colab-df-convert\" onclick=\"convertToInteractive('df-c90c922b-1afc-46c3-b49b-2e62bfc50402')\"\n"," title=\"Convert this dataframe to an interactive table.\"\n"," style=\"display:none;\">\n"," \n"," <svg xmlns=\"http://www.w3.org/2000/svg\" height=\"24px\"viewBox=\"0 0 24 24\"\n"," width=\"24px\">\n"," <path d=\"M0 0h24v24H0V0z\" fill=\"none\"/>\n"," <path d=\"M18.56 5.44l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94zm-11 1L8.5 8.5l.94-2.06 2.06-.94-2.06-.94L8.5 2.5l-.94 2.06-2.06.94zm10 10l.94 2.06.94-2.06 2.06-.94-2.06-.94-.94-2.06-.94 2.06-2.06.94z\"/><path d=\"M17.41 7.96l-1.37-1.37c-.4-.4-.92-.59-1.43-.59-.52 0-1.04.2-1.43.59L10.3 9.45l-7.72 7.72c-.78.78-.78 2.05 0 2.83L4 21.41c.39.39.9.59 1.41.59.51 0 1.02-.2 1.41-.59l7.78-7.78 2.81-2.81c.8-.78.8-2.07 0-2.86zM5.41 20L4 18.59l7.72-7.72 1.47 1.35L5.41 20z\"/>\n"," </svg>\n"," </button>\n"," \n"," <style>\n"," .colab-df-container {\n"," display:flex;\n"," flex-wrap:wrap;\n"," gap: 12px;\n"," }\n","\n"," .colab-df-convert {\n"," background-color: #E8F0FE;\n"," border: none;\n"," border-radius: 50%;\n"," cursor: pointer;\n"," display: none;\n"," fill: #1967D2;\n"," height: 32px;\n"," padding: 0 0 0 0;\n"," width: 32px;\n"," }\n","\n"," .colab-df-convert:hover {\n"," background-color: #E2EBFA;\n"," box-shadow: 0px 1px 2px rgba(60, 64, 67, 0.3), 0px 1px 3px 1px rgba(60, 64, 67, 0.15);\n"," fill: #174EA6;\n"," }\n","\n"," [theme=dark] .colab-df-convert {\n"," background-color: #3B4455;\n"," fill: #D2E3FC;\n"," }\n","\n"," [theme=dark] .colab-df-convert:hover {\n"," background-color: #434B5C;\n"," box-shadow: 0px 1px 3px 1px rgba(0, 0, 0, 0.15);\n"," filter: drop-shadow(0px 1px 2px rgba(0, 0, 0, 0.3));\n"," fill: #FFFFFF;\n"," }\n"," </style>\n","\n"," <script>\n"," const buttonEl =\n"," document.querySelector('#df-c90c922b-1afc-46c3-b49b-2e62bfc50402 button.colab-df-convert');\n"," buttonEl.style.display =\n"," google.colab.kernel.accessAllowed ? 'block' : 'none';\n","\n"," async function convertToInteractive(key) {\n"," const element = document.querySelector('#df-c90c922b-1afc-46c3-b49b-2e62bfc50402');\n"," const dataTable =\n"," await google.colab.kernel.invokeFunction('convertToInteractive',\n"," [key], {});\n"," if (!dataTable) return;\n","\n"," const docLinkHtml = 'Like what you see? Visit the ' +\n"," '<a target=\"_blank\" href=https://colab.research.google.com/notebooks/data_table.ipynb>data table notebook</a>'\n"," + ' to learn more about interactive tables.';\n"," element.innerHTML = '';\n"," dataTable['output_type'] = 'display_data';\n"," await google.colab.output.renderOutput(dataTable, element);\n"," const docLink = document.createElement('div');\n"," docLink.innerHTML = docLinkHtml;\n"," element.appendChild(docLink);\n"," }\n"," </script>\n"," </div>\n"," </div>\n"," "]},"metadata":{},"execution_count":24}]},{"cell_type":"code","source":["import pickle\n","#Writing different model files to file\n","with open('/content/drive/MyDrive/AF/modelForPrediction.sav','wb') as f:\n"," pickle.dump(model,f)"],"metadata":{"id":"G7OMWIDbic93","executionInfo":{"status":"ok","timestamp":1650735046948,"user_tz":-330,"elapsed":600,"user":{"displayName":"Nivethika gnanaseelan","userId":"18142400286402032214"}}},"execution_count":25,"outputs":[]},{"cell_type":"code","source":["filename='/content/drive/MyDrive/AF/modelForPrediction.sav'\n","loaded_model=pickle.load(open(filename,'rb'))\n","\n","\n","feature=extract_feature(\"/content/drive/MyDrive/speech-emotion-recognition-ravdess-data (2)/Actor_40/03-01-06-01-01-01-16.wav\",mfcc=True,chroma=True,mel=True)\n","feature=feature.reshape(1,-1)\n","print(feature)\n","prediction=loaded_model.predict(feature)\n","prediction"],"metadata":{"colab":{"base_uri":"https://localhost:8080/"},"id":"5-vHm6yTk7iC","executionInfo":{"status":"ok","timestamp":1650735067239,"user_tz":-330,"elapsed":415,"user":{"displayName":"Nivethika gnanaseelan","userId":"18142400286402032214"}},"outputId":"a5424af3-f3d4-4c4b-87d4-366a6df77263"},"execution_count":27,"outputs":[{"output_type":"stream","name":"stdout","text":["[[-5.99025085e+02 5.93243599e+01 -5.27459002e+00 4.39783335e+00\n"," 1.46608377e+00 2.26468062e+00 -1.13505497e+01 -3.82702208e+00\n"," -1.08017721e+01 -8.76068211e+00 -5.85530376e+00 -1.98446602e-01\n"," -6.51101303e+00 -1.16964912e+01 -2.74854398e+00 3.07904196e+00\n"," -4.09571505e+00 -4.56286955e+00 -6.08998823e+00 -4.76240015e+00\n"," -3.67616773e+00 -4.29374743e+00 -3.02783442e+00 -1.85411525e+00\n"," 3.08616728e-01 3.30577731e+00 1.52366447e+00 2.43658185e+00\n"," 2.26087308e+00 1.90570927e+00 7.73032188e-01 4.26568794e+00\n"," 3.27769446e+00 5.57465136e-01 1.60255164e-01 -2.64153302e-01\n"," -2.28120732e+00 -9.44285929e-01 8.79663110e-01 -4.63463128e-01\n"," 6.16392136e-01 5.46798766e-01 5.16413808e-01 5.07633269e-01\n"," 5.01158953e-01 5.11150181e-01 5.08186102e-01 5.21526992e-01\n"," 5.54252863e-01 5.89049160e-01 5.89862704e-01 6.26541495e-01]]\n"]},{"output_type":"execute_result","data":{"text/plain":["array(['fearful'], dtype='<U7')"]},"metadata":{},"execution_count":27}]}]}
\ No newline at end of file
"""
ASGI config for audiocheck project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'audiocheck.settings')
application = get_asgi_application()
from django import forms
from django.apps import AppConfig
from django import forms
from audiocheck.models import Audio_store
class AudioForm(forms.ModelForm):
class Meta:
model=Audio_store
fields=['record']
\ No newline at end of file
from django.db import models
from django.apps import AppConfig
class Audio_store(models.Model):
record=models.FileField(upload_to='')
class Meta:
db_table='Audio_store'
\ No newline at end of file
"""
Django settings for audiocheck project.
Generated by 'django-admin startproject' using Django 4.0.4.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
"""
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
PRODUCT_MODEL = 'Audio_store'
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-i!zl!#ao+%h^w*8rua7fd#*tc52yn4ak$#etwu%k7)p3khqwuu'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'audiocheck',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'audiocheck.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'audiocheck.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/
STATIC_URL = 'static/'
# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
STATIC_URL = '/static/'
MEDIA_URL='/media/'
MEDIA_ROOT=os.path.join(BASE_DIR,'media')
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="audio" method = "post" enctype="multipart/form-data">
{% csrf_token %}
{{ form }}
<button type="submit">Upload</button>
</form>
</body>
</html>
\ No newline at end of file
from django.contrib import admin
from django.urls import path
from . import views
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('audio',views.Audio_store),
path('show',views.check),
path('result/',views.Audio_store)
]+ static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
from django.http import HttpResponse
from django.shortcuts import render
import wave as wv
from email.mime import audio
from typing import IO, List
from django.db import models
from unicodedata import numeric
from django.http import HttpResponse
from django.shortcuts import render
import joblib
import numpy as np
import pickle
from django.db import models
import librosa
from pyparsing import replaceWith
from requests import request
import soundfile
import os,glob,pickle
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.neural_network import MLPClassifier
from django.core.files.storage import FileSystemStorage
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
import sqlite3
from .forms import AudioForm
def extract_feature(file_name,mfcc,chroma,mel):
with soundfile.SoundFile(file_name) as sound_file:
X=sound_file.read(dtype='float32')
sample_rate=sound_file.samplerate
if chroma:
stft=np.abs(librosa.stft(X))
result=np.array([])
if mfcc:
mfccs=np.mean(librosa.feature.mfcc(y=X,sr=sample_rate,n_mfcc=40).T,axis=0)
result=np.hstack((result,mfccs))
if chroma:
chroma=np.mean(librosa.feature.chroma_stft(S=stft,sr=sample_rate).T,axis=0)
result=np.hstack((result,chroma))
if mel:
mel=np.mean(librosa.feature.melspectrogram(X,sr=sample_rate).T,axis=0)
resutl=np.hstack((result,mel))
return result
def display_emotion(request):
# print(request)
print("hello")
audio_file=request.GET.get('color','')
print(audio_file)
return render(request, 'show.html', {'one' : audio_file})
def Audio_store(request):
if request.method == 'POST':
form = AudioForm(request.POST,request.FILES or None)
if form.is_valid():
form.save()
return HttpResponse('successfully uploaded')
else:
form =AudioForm()
return render(request, 'aud.htm', {'form' : form})
def check(request):
# Create a SQL connection to our SQLite database
con = sqlite3.connect("db.sqlite3")
cur = con.cursor()
cur.execute('SELECT record FROM Audio_store;')
# The result of a "cursor.execute" can be iterated over by row
rows=cur.fetchall()
result_1d = [row[0] for row in rows]
return render(request, 'show.html', {'row' : result_1d})
# lis=[]
# for row in rows:
# lis.append(row)
# return render(request, 'show.htm', {'row' : rows})
# Be sure to close the connection
con.close()
\ No newline at end of file
"""
WSGI config for audiocheck project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'audiocheck.settings')
application = get_wsgi_application()
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'audiocheck.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="audio" method = "post" enctype="multipart/form-data">
{% csrf_token %}
{{ form }}
<button type="submit">Upload</button>
</form>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
{{one}}
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="text/javascript">
function display()
{
audiodisplay=document.querySelector('input[name=color]:checked').value;
document.querySelector("#selecteraudioname").textContent='The checked radio value is' +audiodisplay;
}
</script>
</head>
<body>
<form action="{% url 'display_emotion' %}" enctype="multipart/form-data">
{% csrf_token %}
{% for student in row %}
<input type="radio" value="{{student}}" id="css" name="color" >
{{student}}
<br>
{% endfor %}
<input type="submit" value="Click" onclick="display()" />
<b style="color:green" id="selecteraudioname"></b>
{{one}}
</form>
</body>
</html>
\ No newline at end of file
"""
ASGI config for audiocheck project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'audiocheck.settings')
application = get_asgi_application()
from django import forms
from django.apps import AppConfig
from django import forms
from audiocheck.models import Audio_store
class AudioForm(forms.ModelForm):
class Meta:
model=Audio_store
fields=['record']
\ No newline at end of file
from django.db import models
from django.apps import AppConfig
class Audio_store(models.Model):
record=models.FileField(upload_to='')
class Meta:
db_table='Audio_store'
\ No newline at end of file
"""
Django settings for audiocheck project.
Generated by 'django-admin startproject' using Django 4.0.4.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/4.0/ref/settings/
"""
from pathlib import Path
import os
# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
PRODUCT_MODEL = 'Audio_store'
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/4.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-i!zl!#ao+%h^w*8rua7fd#*tc52yn4ak$#etwu%k7)p3khqwuu'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = []
# Application definition
INSTALLED_APPS = [
'audiocheck',
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'audiocheck.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'audiocheck.wsgi.application'
# Database
# https://docs.djangoproject.com/en/4.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': BASE_DIR / 'db.sqlite3',
}
}
# Password validation
# https://docs.djangoproject.com/en/4.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/4.0/topics/i18n/
LANGUAGE_CODE = 'en-us'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.0/howto/static-files/
STATIC_URL = 'static/'
# Default primary key field type
# https://docs.djangoproject.com/en/4.0/ref/settings/#default-auto-field
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
STATIC_URL = '/static/'
MEDIA_URL='/media/'
MEDIA_ROOT=os.path.join(BASE_DIR,'media')
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="audio" method = "post" enctype="multipart/form-data">
{% csrf_token %}
{{ form }}
<button type="submit">Upload</button>
</form>
</body>
</html>
\ No newline at end of file
from django.contrib import admin
from django.urls import path
from . import views
from django.conf import settings
from django.conf.urls.static import static
urlpatterns = [
path('admin/', admin.site.urls),
path('audio',views.Audio_store),
path('show',views.check),
path('result/',views.Audio_store)
]+ static(settings.MEDIA_URL,document_root=settings.MEDIA_ROOT)
from django.http import HttpResponse
from django.shortcuts import render
import wave as wv
from email.mime import audio
from typing import IO, List
from django.db import models
from unicodedata import numeric
from django.http import HttpResponse
from django.shortcuts import render
import joblib
import numpy as np
import pickle
from django.db import models
import librosa
from pyparsing import replaceWith
from requests import request
import soundfile
import os,glob,pickle
import numpy as np
from sklearn.model_selection import train_test_split
from sklearn.neural_network import MLPClassifier
from django.core.files.storage import FileSystemStorage
from django.core.files.storage import default_storage
from django.core.files.base import ContentFile
import sqlite3
from .forms import AudioForm
def extract_feature(file_name,mfcc,chroma,mel):
with soundfile.SoundFile(file_name) as sound_file:
X=sound_file.read(dtype='float32')
sample_rate=sound_file.samplerate
if chroma:
stft=np.abs(librosa.stft(X))
result=np.array([])
if mfcc:
mfccs=np.mean(librosa.feature.mfcc(y=X,sr=sample_rate,n_mfcc=40).T,axis=0)
result=np.hstack((result,mfccs))
if chroma:
chroma=np.mean(librosa.feature.chroma_stft(S=stft,sr=sample_rate).T,axis=0)
result=np.hstack((result,chroma))
if mel:
mel=np.mean(librosa.feature.melspectrogram(X,sr=sample_rate).T,axis=0)
resutl=np.hstack((result,mel))
return result
def display_emotion(request):
# print(request)
print("hello")
audio_file=request.GET.get('color','')
print(audio_file)
return render(request, 'show.html', {'one' : audio_file})
def Audio_store(request):
if request.method == 'POST':
form = AudioForm(request.POST,request.FILES or None)
if form.is_valid():
form.save()
return HttpResponse('successfully uploaded')
else:
form =AudioForm()
return render(request, 'aud.htm', {'form' : form})
def check(request):
# Create a SQL connection to our SQLite database
con = sqlite3.connect("db.sqlite3")
cur = con.cursor()
cur.execute('SELECT record FROM Audio_store;')
# The result of a "cursor.execute" can be iterated over by row
rows=cur.fetchall()
result_1d = [row[0] for row in rows]
return render(request, 'show.html', {'row' : result_1d})
# lis=[]
# for row in rows:
# lis.append(row)
# return render(request, 'show.htm', {'row' : rows})
# Be sure to close the connection
con.close()
\ No newline at end of file
"""
WSGI config for audiocheck project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'audiocheck.settings')
application = get_wsgi_application()
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'audiocheck.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
<form action="audio" method = "post" enctype="multipart/form-data">
{% csrf_token %}
{{ form }}
<button type="submit">Upload</button>
</form>
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<body>
{{one}}
</body>
</html>
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<script type="text/javascript">
function display()
{
audiodisplay=document.querySelector('input[name=color]:checked').value;
document.querySelector("#selecteraudioname").textContent='The checked radio value is' +audiodisplay;
}
</script>
</head>
<body>
<form action="{% url 'display_emotion' %}" enctype="multipart/form-data">
{% csrf_token %}
{% for student in row %}
<input type="radio" value="{{student}}" id="css" name="color" >
{{student}}
<br>
{% endfor %}
<input type="submit" value="Click" onclick="display()" />
<b style="color:green" id="selecteraudioname"></b>
{{one}}
</form>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment