{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"!pip install pyunpack\n!pip install patool\n!pip install py7zr\n!pip install pathlib","metadata":{"execution":{"iopub.status.busy":"2021-08-10T12:14:58.36756Z","iopub.execute_input":"2021-08-10T12:14:58.367897Z","iopub.status.idle":"2021-08-10T12:15:37.302039Z","shell.execute_reply.started":"2021-08-10T12:14:58.367868Z","shell.execute_reply":"2021-08-10T12:15:37.300928Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2021-08-10T12:15:37.303821Z","iopub.execute_input":"2021-08-10T12:15:37.304115Z","iopub.status.idle":"2021-08-10T12:15:37.31489Z","shell.execute_reply.started":"2021-08-10T12:15:37.304085Z","shell.execute_reply":"2021-08-10T12:15:37.313718Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pwd\nos.getcwd()","metadata":{"execution":{"iopub.status.busy":"2021-08-05T16:18:28.570813Z","iopub.execute_input":"2021-08-05T16:18:28.57111Z","iopub.status.idle":"2021-08-05T16:18:29.305497Z","shell.execute_reply.started":"2021-08-05T16:18:28.57108Z","shell.execute_reply":"2021-08-05T16:18:29.304516Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from pathlib import Path\nimport random\nfrom importlib import reload\nimport warnings\nwarnings.filterwarnings(\"ignore\")\n\n\nimport IPython.display as ipd\nfrom ipywidgets import interact, interactive, fixed, interact_manual\nimport ipywidgets as widgets\nimport librosa, librosa.display\nimport matplotlib.pyplot as plt\nimport numpy as np\nfrom scipy.signal import butter, lfilter\nimport seaborn as sns\nimport soundfile as sf\nfrom tqdm import tqdm_notebook as tqdm\n\nimport librosa\nfrom scipy.io import wavfile\nimport numpy as np\n\nimport glob","metadata":{"execution":{"iopub.status.busy":"2021-08-10T12:15:37.316921Z","iopub.execute_input":"2021-08-10T12:15:37.317235Z","iopub.status.idle":"2021-08-10T12:15:39.954493Z","shell.execute_reply.started":"2021-08-10T12:15:37.317207Z","shell.execute_reply":"2021-08-10T12:15:39.953448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from py7zr import unpack_7zarchive\nimport shutil\n\nshutil.register_unpack_format('7zip', ['.7z'], unpack_7zarchive)\nshutil.unpack_archive('/kaggle/input/tensorflow-speech-recognition-challenge/train.7z', '/kaggle/working/tensorflow-speech-recognition-challenge/')","metadata":{"execution":{"iopub.status.busy":"2021-08-10T12:15:39.956355Z","iopub.execute_input":"2021-08-10T12:15:39.956771Z","iopub.status.idle":"2021-08-10T12:18:39.044171Z","shell.execute_reply.started":"2021-08-10T12:15:39.95673Z","shell.execute_reply":"2021-08-10T12:18:39.043059Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path_base = Path('/kaggle/working/tensorflow-speech-recognition-challenge/train')\npaths_train = list(path_base.glob('**'))\npaths_train","metadata":{"execution":{"iopub.status.busy":"2021-08-10T12:18:46.923876Z","iopub.execute_input":"2021-08-10T12:18:46.924343Z","iopub.status.idle":"2021-08-10T12:18:47.263252Z","shell.execute_reply.started":"2021-08-10T12:18:46.924296Z","shell.execute_reply":"2021-08-10T12:18:47.261882Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print([str(path).split('/')[-1] for path in paths_train] )","metadata":{"execution":{"iopub.status.busy":"2021-08-10T12:30:51.027971Z","iopub.execute_input":"2021-08-10T12:30:51.028362Z","iopub.status.idle":"2021-08-10T12:30:51.03638Z","shell.execute_reply.started":"2021-08-10T12:30:51.028328Z","shell.execute_reply":"2021-08-10T12:30:51.034313Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"os.listdir('/kaggle/working/tensorflow-speech-recognition-challenge/train/audio')","metadata":{"execution":{"iopub.status.busy":"2021-08-05T16:21:35.94607Z","iopub.execute_input":"2021-08-05T16:21:35.946343Z","iopub.status.idle":"2021-08-05T16:21:36.792968Z","shell.execute_reply.started":"2021-08-05T16:21:35.946318Z","shell.execute_reply":"2021-08-05T16:21:36.792051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"trial_path = '/kaggle/working/tensorflow-speech-recognition-challenge/train/audio'\ncnt = 0\nfor dirnames, _, filenames in os.walk(trial_path):\n    cnt += len(filenames)","metadata":{"execution":{"iopub.status.busy":"2021-08-05T16:21:36.795639Z","iopub.execute_input":"2021-08-05T16:21:36.796062Z","iopub.status.idle":"2021-08-05T16:21:36.916451Z","shell.execute_reply.started":"2021-08-05T16:21:36.796031Z","shell.execute_reply":"2021-08-05T16:21:36.915628Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"cnt","metadata":{"execution":{"iopub.status.busy":"2021-08-05T16:21:36.918115Z","iopub.execute_input":"2021-08-05T16:21:36.918577Z","iopub.status.idle":"2021-08-05T16:21:36.923722Z","shell.execute_reply.started":"2021-08-05T16:21:36.918534Z","shell.execute_reply":"2021-08-05T16:21:36.922968Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"path_of_audios = '/kaggle/working/tensorflow-speech-recognition-challenge/train/audio/house'\nhouse_audio = os.listdir(path_of_audios) #List of all file names inside house folder\n\n\nfor i in range(300,400):\n    print(path_of_audios+'/'+house_audio[i])\n    \nsr = 16000 #hz (sample rate)","metadata":{"execution":{"iopub.status.busy":"2021-08-10T12:18:39.046037Z","iopub.execute_input":"2021-08-10T12:18:39.046556Z","iopub.status.idle":"2021-08-10T12:18:39.069001Z","shell.execute_reply.started":"2021-08-10T12:18:39.046503Z","shell.execute_reply":"2021-08-10T12:18:39.067858Z"},"collapsed":true,"jupyter":{"outputs_hidden":true},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"idx = 7\nsamples, sample_rate = librosa.load(path_of_audios+'/'+house_audio[idx], sr = sr)\nsamples.shape","metadata":{"execution":{"iopub.status.busy":"2021-08-10T12:18:39.070687Z","iopub.execute_input":"2021-08-10T12:18:39.07118Z","iopub.status.idle":"2021-08-10T12:18:40.256618Z","shell.execute_reply.started":"2021-08-10T12:18:39.07114Z","shell.execute_reply":"2021-08-10T12:18:40.255592Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ipd.Audio(samples, rate = sr)","metadata":{"execution":{"iopub.status.busy":"2021-08-10T12:18:40.258999Z","iopub.execute_input":"2021-08-10T12:18:40.259333Z","iopub.status.idle":"2021-08-10T12:18:46.910393Z","shell.execute_reply.started":"2021-08-10T12:18:40.259303Z","shell.execute_reply":"2021-08-10T12:18:46.908405Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"ipd.Audio(path_of_audios+'/'+house_audio[idx])","metadata":{"execution":{"iopub.status.busy":"2021-08-10T12:18:46.912692Z","iopub.execute_input":"2021-08-10T12:18:46.913191Z","iopub.status.idle":"2021-08-10T12:18:46.92193Z","shell.execute_reply.started":"2021-08-10T12:18:46.913142Z","shell.execute_reply":"2021-08-10T12:18:46.920653Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"samples","metadata":{}},{"cell_type":"code","source":"fig = plt.figure(figsize=(20,13))\nx_values = np.linspace(0,sr/len(samples),sr)\ny_values = samples\nax = plt.gca()\nax.set_title('Raw wave of '+path_of_audios+'/'+house_audio[idx])\nax.set_xlabel('Time')\nax.set_ylabel('Amplitude')\nplt.plot(x_values, y_values)","metadata":{"execution":{"iopub.status.busy":"2021-08-05T16:21:36.995385Z","iopub.execute_input":"2021-08-05T16:21:36.995745Z","iopub.status.idle":"2021-08-05T16:21:37.450295Z","shell.execute_reply.started":"2021-08-05T16:21:36.99571Z","shell.execute_reply":"2021-08-05T16:21:37.447299Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"16*3","metadata":{"execution":{"iopub.status.busy":"2021-08-05T16:21:37.451574Z","iopub.status.idle":"2021-08-05T16:21:37.452032Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"resamples = librosa.resample(samples, sr, 8000)\nipd.Audio(resamples, rate=8000)","metadata":{"execution":{"iopub.status.busy":"2021-08-05T16:21:37.45317Z","iopub.status.idle":"2021-08-05T16:21:37.453601Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# sample rate is how many complete cycles we have in one second","metadata":{"execution":{"iopub.status.busy":"2021-08-05T16:21:37.45478Z","iopub.status.idle":"2021-08-05T16:21:37.455182Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"labels=[ 'dog', 'one', 'down', 'right', 'cat', 'bed', 'up', 'eight', 'marvin', 'six', 'nine', 'four',\n        'five', 'yes', 'three', 'wow', 'sheila', 'zero', 'seven', 'happy', 'go', 'bird', 'two', 'stop', 'off', 'tree',  'house', 'on', 'left', 'no']","metadata":{"execution":{"iopub.status.busy":"2021-08-10T12:31:30.349045Z","iopub.execute_input":"2021-08-10T12:31:30.349446Z","iopub.status.idle":"2021-08-10T12:31:30.355399Z","shell.execute_reply.started":"2021-08-10T12:31:30.349412Z","shell.execute_reply":"2021-08-10T12:31:30.354194Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(labels)","metadata":{"execution":{"iopub.status.busy":"2021-08-10T12:31:32.470808Z","iopub.execute_input":"2021-08-10T12:31:32.471396Z","iopub.status.idle":"2021-08-10T12:31:32.478653Z","shell.execute_reply.started":"2021-08-10T12:31:32.471342Z","shell.execute_reply":"2021-08-10T12:31:32.47762Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# 1- resample all files\n# 2- Keep only the files that belong to our labels.\n# x is the features (It is the amplitude in the time domain). (all_wave)\n# y is the labels. (all_label)\n\nall_wave = []\nall_label = []\npath = '/kaggle/working/tensorflow-speech-recognition-challenge/train/audio/'\nfor label in labels:\n    waves = [file for file in os.listdir(path+label) if file.endswith('.wav')] \n    for wav in waves:\n        samples,sr = librosa.load(path+label+'/'+wav, sr=16_000)\n        resamples = librosa.resample(samples, sr, 8_000)\n        \n        if len(resamples)==8_000:\n            all_wave.append(resamples)\n            all_label.append(label)","metadata":{"execution":{"iopub.status.busy":"2021-08-10T12:31:55.90411Z","iopub.execute_input":"2021-08-10T12:31:55.904704Z","iopub.status.idle":"2021-08-10T12:51:55.116167Z","shell.execute_reply.started":"2021-08-10T12:31:55.904649Z","shell.execute_reply":"2021-08-10T12:51:55.115089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(len(all_wave))","metadata":{"execution":{"iopub.status.busy":"2021-08-10T15:39:48.399421Z","iopub.status.idle":"2021-08-10T15:39:48.39986Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range(10):\n    print(all_wave[i].shape)","metadata":{"execution":{"iopub.status.busy":"2021-08-10T12:51:55.12697Z","iopub.execute_input":"2021-08-10T12:51:55.127286Z","iopub.status.idle":"2021-08-10T12:51:55.145032Z","shell.execute_reply.started":"2021-08-10T12:51:55.127257Z","shell.execute_reply":"2021-08-10T12:51:55.143795Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Building The Model","metadata":{}},{"cell_type":"markdown","source":"## preparing the output","metadata":{}},{"cell_type":"code","source":"from sklearn.preprocessing import LabelEncoder\nle = LabelEncoder()\ny=le.fit_transform(all_label)\nclasses= list(le.classes_)","metadata":{"execution":{"iopub.status.busy":"2021-08-10T12:51:55.146597Z","iopub.execute_input":"2021-08-10T12:51:55.146916Z","iopub.status.idle":"2021-08-10T12:51:55.187043Z","shell.execute_reply.started":"2021-08-10T12:51:55.146866Z","shell.execute_reply":"2021-08-10T12:51:55.185968Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"from keras.utils import np_utils\ny = np_utils.to_categorical(y, num_classes = len(labels))","metadata":{"execution":{"iopub.status.busy":"2021-08-10T12:51:55.188595Z","iopub.execute_input":"2021-08-10T12:51:55.188905Z","iopub.status.idle":"2021-08-10T12:52:02.34131Z","shell.execute_reply.started":"2021-08-10T12:51:55.188877Z","shell.execute_reply":"2021-08-10T12:52:02.340185Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"y.shape","metadata":{"execution":{"iopub.status.busy":"2021-08-10T12:52:02.342855Z","iopub.execute_input":"2021-08-10T12:52:02.343478Z","iopub.status.idle":"2021-08-10T12:52:02.349476Z","shell.execute_reply.started":"2021-08-10T12:52:02.343429Z","shell.execute_reply":"2021-08-10T12:52:02.348635Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Reshaping the Input","metadata":{}},{"cell_type":"code","source":"all_wave = np.array(all_wave).reshape(-1,8000,1)","metadata":{"execution":{"iopub.status.busy":"2021-08-10T12:52:02.350525Z","iopub.execute_input":"2021-08-10T12:52:02.350968Z","iopub.status.idle":"2021-08-10T12:52:03.570519Z","shell.execute_reply.started":"2021-08-10T12:52:02.350937Z","shell.execute_reply":"2021-08-10T12:52:03.569251Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"all_wave.shape","metadata":{"execution":{"iopub.status.busy":"2021-08-10T12:52:03.574351Z","iopub.execute_input":"2021-08-10T12:52:03.574816Z","iopub.status.idle":"2021-08-10T12:52:03.583207Z","shell.execute_reply.started":"2021-08-10T12:52:03.574776Z","shell.execute_reply":"2021-08-10T12:52:03.582051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Splitting Into Train and Validation Datasets","metadata":{}},{"cell_type":"code","source":"from sklearn.model_selection import train_test_split\n\nx_tr, x_val, y_tr , y_val = train_test_split(all_wave,y, stratify = y, test_size = 0.2, shuffle =True)","metadata":{"execution":{"iopub.status.busy":"2021-08-10T12:52:03.58502Z","iopub.execute_input":"2021-08-10T12:52:03.58548Z","iopub.status.idle":"2021-08-10T12:52:13.123627Z","shell.execute_reply.started":"2021-08-10T12:52:03.585432Z","shell.execute_reply":"2021-08-10T12:52:13.121988Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"## Keras Model","metadata":{}},{"cell_type":"code","source":"from keras.layers import Dense, Dropout, Flatten, Conv1D, Input, MaxPooling1D\nfrom keras.models import Model\nfrom keras.callbacks import EarlyStopping, ModelCheckpoint\nfrom keras import backend as K","metadata":{"execution":{"iopub.status.busy":"2021-08-10T12:52:13.125584Z","iopub.execute_input":"2021-08-10T12:52:13.126148Z","iopub.status.idle":"2021-08-10T12:52:13.132768Z","shell.execute_reply.started":"2021-08-10T12:52:13.126078Z","shell.execute_reply":"2021-08-10T12:52:13.131243Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"inputs = Input(shape=(8000,1))\n\n# First Conv1D layer\nconv = Conv1D(8, 12, padding=\"valid\", activation='relu', strides=1)(inputs)\nconv = MaxPooling1D(3)(conv)\nconv = Dropout(0.3)(conv)\n\n# Second Conv1D layer\nconv = Conv1D(16, 11, padding=\"valid\", activation='relu', strides=1)(conv)\nconv = MaxPooling1D(3)(conv)\nconv = Dropout(0.3)(conv)\n\n# Third Conv1D layer\nconv = Conv1D(32, 9, padding=\"valid\", activation='relu', strides=1)(conv)\nconv = MaxPooling1D(pool_size=3)(conv)\nconv = Dropout(0.3)(conv)\n\n# Fourth Conv1D layer\nconv = Conv1D(64,7, padding=\"valid\", activation='relu', strides=1)(conv)\nconv = MaxPooling1D(3)(conv)\nconv = Dropout(0.3)(conv)\n\nconv = Flatten()(conv)\n\n#Dense Layer1\nconv = Dense(128, activation = 'relu')(conv)\nconv = Dropout(0.3)(conv)\n\n#Dense Layer2\nconv = Dense(128, activation = 'relu')(conv)\nconv = Dropout(0.3)(conv)\n\n# The output Function of the last layer is not ReLU, it's SofMax\n#len(labels) is 10\noutputs = Dense(len(labels), activation='softmax')(conv)\n\nmodel = Model(inputs, outputs)\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2021-08-10T12:52:13.134706Z","iopub.execute_input":"2021-08-10T12:52:13.135171Z","iopub.status.idle":"2021-08-10T12:52:13.395669Z","shell.execute_reply.started":"2021-08-10T12:52:13.135101Z","shell.execute_reply":"2021-08-10T12:52:13.394482Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"model.compile(loss='categorical_crossentropy', optimizer = 'adam', metrics=['accuracy'])\n\nes = EarlyStopping(monitor = 'val_loss', mode='min', verbose=1, patience = 10)\n\nmc = ModelCheckpoint('kaggle/working/best_model.hdf5', monitor='val_acc', verbose=1, save_best_only=True, \n                     mode='max')\nhistory = model.fit(x_tr, y_tr, callbacks=[es,mc],validation_data=(x_val,y_val),\n          epochs=100, batch_size = 32)","metadata":{"execution":{"iopub.status.busy":"2021-08-10T12:52:13.39947Z","iopub.execute_input":"2021-08-10T12:52:13.399825Z","iopub.status.idle":"2021-08-10T15:39:48.396379Z","shell.execute_reply.started":"2021-08-10T12:52:13.399793Z","shell.execute_reply":"2021-08-10T15:39:48.39407Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# model.save('kaggle/working/')\n\nmodel.save(\"my_h5_model.h5\")","metadata":{"execution":{"iopub.status.busy":"2021-08-10T15:42:10.943617Z","iopub.execute_input":"2021-08-10T15:42:10.944078Z","iopub.status.idle":"2021-08-10T15:42:11.015474Z","shell.execute_reply.started":"2021-08-10T15:42:10.944041Z","shell.execute_reply":"2021-08-10T15:42:11.014413Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"from keras.models import load_model\n\nmodel = load_model('my_h5_model.h5')\nmodel.summary()","metadata":{"execution":{"iopub.status.busy":"2021-08-10T15:42:58.403887Z","iopub.execute_input":"2021-08-10T15:42:58.404275Z","iopub.status.idle":"2021-08-10T15:42:58.622719Z","shell.execute_reply.started":"2021-08-10T15:42:58.404246Z","shell.execute_reply":"2021-08-10T15:42:58.621523Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def predict(audio):\n    prob = model.predict(audio.reshape(-1,8_000,1)) #prob is a vector of 10 values\n    index = np.argmax(prob[0])\n    return classes[index]","metadata":{"execution":{"iopub.status.busy":"2021-08-10T15:43:02.828419Z","iopub.execute_input":"2021-08-10T15:43:02.82878Z","iopub.status.idle":"2021-08-10T15:43:02.83569Z","shell.execute_reply.started":"2021-08-10T15:43:02.828751Z","shell.execute_reply":"2021-08-10T15:43:02.8339Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"samples = x_tr[24564].flatten()\nprint(predict(samples))\nipd.Audio(samples,rate=8_000)","metadata":{"execution":{"iopub.status.busy":"2021-08-10T15:43:57.807848Z","iopub.execute_input":"2021-08-10T15:43:57.808255Z","iopub.status.idle":"2021-08-10T15:43:57.870931Z","shell.execute_reply.started":"2021-08-10T15:43:57.80822Z","shell.execute_reply":"2021-08-10T15:43:57.869842Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import sounddevice as sd\nimport soundfile as sf\n\nsamplerate = 16000  \nduration = 1 # seconds\nfilename = 'yes.wav'\nprint(\"start\")\nmydata = sd.rec(int(samplerate * duration), samplerate=samplerate,channels=1, blocking=True)\nprint(\"end\")\nsd.wait()\nsf.write(filename, mydata, samplerate)","metadata":{"execution":{"iopub.status.busy":"2021-08-10T15:43:07.598703Z","iopub.execute_input":"2021-08-10T15:43:07.59906Z","iopub.status.idle":"2021-08-10T15:43:07.637594Z","shell.execute_reply.started":"2021-08-10T15:43:07.59903Z","shell.execute_reply":"2021-08-10T15:43:07.636237Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#reading the voice commands\nsamples, sample_rate = librosa.load(filepath + '/' + 'stop.wav', sr = 16000)\nsamples = librosa.resample(samples, sample_rate, 8000)\nipd.Audio(samples,rate=8000)     ","metadata":{"execution":{"iopub.status.busy":"2021-08-05T16:21:37.484617Z","iopub.status.idle":"2021-08-05T16:21:37.485015Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"predict(samples)","metadata":{"execution":{"iopub.status.busy":"2021-08-05T16:21:37.48584Z","iopub.status.idle":"2021-08-05T16:21:37.486231Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"Why do we need a validation dataset?\nHow many epochs did you need to train your model?\nWhat was your stopping criteria to stop training?\nWhich libraries did you use for building your model and converting the audio files?\nWhat was the proportion you used to split your data into train and validation datasets?\nHow many parameters do you have in your model?\nWhat is your optimizer?\n\nWhy did you use Conv1D not Conv2D?\nWhat is the sample rate that you used to train your model, and why?\nWhat is your evaluation metric?\nWhat is the spectrogram representation?\nWhat is the sampling rate?","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}