{"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":"#Calling the Libraries \nimport numpy as np\nimport pandas as pd\nimport librosa\nfrom IPython.display import Audio, display\nimport IPython\nimport librosa.display\nimport IPython.display as ipd\nimport matplotlib.pyplot as plt\n","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Reading the mp3 files using glob. ","metadata":{}},{"cell_type":"code","source":"from glob import glob\n\nfilenames = glob('../input/dlsprint/train_files/*.mp3')\n\nlabels = []\nfor each in filenames:\n    each = each.split('/')[-1][:-3]\n    labels.append(each.split('_')[-2])","metadata":{"execution":{"iopub.status.busy":"2022-07-30T21:40:31.862587Z","iopub.execute_input":"2022-07-30T21:40:31.863653Z","iopub.status.idle":"2022-07-30T21:40:37.325074Z","shell.execute_reply.started":"2022-07-30T21:40:31.863612Z","shell.execute_reply":"2022-07-30T21:40:37.324069Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Printing the first 5 files","metadata":{}},{"cell_type":"code","source":"filenames[1:5]","metadata":{"execution":{"iopub.status.busy":"2022-07-30T21:40:39.764676Z","iopub.execute_input":"2022-07-30T21:40:39.765526Z","iopub.status.idle":"2022-07-30T21:40:39.776716Z","shell.execute_reply.started":"2022-07-30T21:40:39.765470Z","shell.execute_reply":"2022-07-30T21:40:39.775614Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Code to ignore warnings","metadata":{}},{"cell_type":"code","source":"import warnings \nwarnings.filterwarnings('ignore')","metadata":{"execution":{"iopub.status.busy":"2022-07-30T21:40:42.886741Z","iopub.execute_input":"2022-07-30T21:40:42.887122Z","iopub.status.idle":"2022-07-30T21:40:42.891502Z","shell.execute_reply.started":"2022-07-30T21:40:42.887091Z","shell.execute_reply":"2022-07-30T21:40:42.890566Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib.pyplot as plt\nimport numpy as np\nimport csv\nimport scipy\nfrom scipy.io import wavfile\nimport os\nfrom sklearn.ensemble import RandomForestClassifier\nfrom sklearn.model_selection import train_test_split, ParameterGrid\nfrom sklearn.metrics import accuracy_score, precision_recall_fscore_support, confusion_matrix\nfrom sklearn.neural_network import MLPClassifier\nfrom sklearn.model_selection import GridSearchCV\nfrom sklearn.metrics import classification_report","metadata":{"execution":{"iopub.status.busy":"2022-07-30T21:40:44.804866Z","iopub.execute_input":"2022-07-30T21:40:44.805587Z","iopub.status.idle":"2022-07-30T21:40:44.927805Z","shell.execute_reply.started":"2022-07-30T21:40:44.805548Z","shell.execute_reply":"2022-07-30T21:40:44.926660Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"10 Audio files, Comments and waveform","metadata":{}},{"cell_type":"markdown","source":"1st","metadata":{}},{"cell_type":"code","source":"files , sr = librosa.load(filenames[20])\nprint(files)\nplt.plot(files)\n\nIPython.display.Audio(filenames[20])\n#tate gobeshona o biggan chorchar obadh sujog royeche. No noise. Clean voice","metadata":{"execution":{"iopub.status.busy":"2022-07-30T21:40:47.736674Z","iopub.execute_input":"2022-07-30T21:40:47.737614Z","iopub.status.idle":"2022-07-30T21:40:49.205715Z","shell.execute_reply.started":"2022-07-30T21:40:47.737577Z","shell.execute_reply":"2022-07-30T21:40:49.204723Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"2nd","metadata":{}},{"cell_type":"code","source":"files , sr = librosa.load(filenames[21])\nprint(files)\nplt.plot(files)\n\nIPython.display.Audio(filenames[21])\n#obosorgrohoner por jadobpur bissobiddaloyer prodhan chilen sunil kumar sen. Too fast. Not easy to understant what is saying","metadata":{"execution":{"iopub.status.busy":"2022-07-26T13:13:52.712371Z","iopub.execute_input":"2022-07-26T13:13:52.712745Z","iopub.status.idle":"2022-07-26T13:13:53.728945Z","shell.execute_reply.started":"2022-07-26T13:13:52.712716Z","shell.execute_reply":"2022-07-26T13:13:53.727791Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"3rd","metadata":{}},{"cell_type":"code","source":"files , sr = librosa.load(filenames[22])\nprint(files)\nplt.plot(files)\n\nIPython.display.Audio(filenames[22])\n# tar pita rofikul hoque. Noise = sound of car. ","metadata":{"execution":{"iopub.status.busy":"2022-07-26T13:14:48.996903Z","iopub.execute_input":"2022-07-26T13:14:48.997294Z","iopub.status.idle":"2022-07-26T13:14:49.919092Z","shell.execute_reply.started":"2022-07-26T13:14:48.997259Z","shell.execute_reply":"2022-07-26T13:14:49.918089Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"4th","metadata":{}},{"cell_type":"code","source":"files , sr = librosa.load(filenames[23])\nprint(files)\nplt.plot(files)\n\nIPython.display.Audio(filenames[23])\n#musics academy theke prosikhon grohon koren. Too fast. Unclear. ","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:58:06.211181Z","iopub.execute_input":"2022-07-26T16:58:06.211588Z","iopub.status.idle":"2022-07-26T16:58:06.945653Z","shell.execute_reply.started":"2022-07-26T16:58:06.211552Z","shell.execute_reply":"2022-07-26T16:58:06.944508Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"5th","metadata":{}},{"cell_type":"code","source":"files , sr = librosa.load(filenames[24])\nprint(files)\nplt.plot(files)\n\nIPython.display.Audio(filenames[24])\n#ini dui meyade reyal madrider sovapoti hisebe dayitto palon koren. \n#Noise of croud .","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:57:56.842859Z","iopub.execute_input":"2022-07-26T16:57:56.843319Z","iopub.status.idle":"2022-07-26T16:57:57.914418Z","shell.execute_reply.started":"2022-07-26T16:57:56.843279Z","shell.execute_reply":"2022-07-26T16:57:57.913347Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"6th","metadata":{}},{"cell_type":"code","source":"files , sr = librosa.load(filenames[25])\nprint(files)\nplt.plot(files)\n\nIPython.display.Audio(filenames[25])\n#binodpur union khulna bivager magura jelar mohammodpur upojelar ontorgoto. \n#Slightly fast. ","metadata":{"execution":{"iopub.status.busy":"2022-07-26T16:57:45.627082Z","iopub.execute_input":"2022-07-26T16:57:45.628076Z","iopub.status.idle":"2022-07-26T16:57:46.422601Z","shell.execute_reply.started":"2022-07-26T16:57:45.628030Z","shell.execute_reply":"2022-07-26T16:57:46.421443Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"7th","metadata":{}},{"cell_type":"code","source":"files , sr = librosa.load(filenames[26])\nprint(files)\nplt.plot(files)\n\nIPython.display.Audio(filenames[26])\n#thi dhacher ei mondirti somapto hole europ er brihottoro bouddho mondir hobe. \n#Adenoidal voice so little hard to understand. But okey. ","metadata":{"execution":{"iopub.status.busy":"2022-07-26T13:44:56.496846Z","iopub.execute_input":"2022-07-26T13:44:56.497217Z","iopub.status.idle":"2022-07-26T13:44:57.580787Z","shell.execute_reply.started":"2022-07-26T13:44:56.497183Z","shell.execute_reply":"2022-07-26T13:44:57.579584Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"8th","metadata":{}},{"cell_type":"code","source":"files , sr = librosa.load(filenames[27])\nprint(files)\nplt.plot(files)\n\nIPython.display.Audio(filenames[27])\n#er moddho diyei karjokori vabe prothom islami rastro protisthito hoyechilo. \n#Up and down intensity. ","metadata":{"execution":{"iopub.status.busy":"2022-07-26T13:50:46.805008Z","iopub.execute_input":"2022-07-26T13:50:46.805497Z","iopub.status.idle":"2022-07-26T13:50:47.945775Z","shell.execute_reply.started":"2022-07-26T13:50:46.805445Z","shell.execute_reply":"2022-07-26T13:50:47.944570Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"9th","metadata":{}},{"cell_type":"code","source":"files , sr = librosa.load(filenames[28])\nprint(files)\nplt.plot(files)\n\nIPython.display.Audio(filenames[28])\n#bisesh biddaloy ti ayshar nijosso prokolpo ebong eti aysha education society porichalona kore \n# plain voice. No noise. ","metadata":{"execution":{"iopub.status.busy":"2022-07-26T13:52:38.057517Z","iopub.execute_input":"2022-07-26T13:52:38.058737Z","iopub.status.idle":"2022-07-26T13:52:39.279850Z","shell.execute_reply.started":"2022-07-26T13:52:38.058691Z","shell.execute_reply":"2022-07-26T13:52:39.278670Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"10th","metadata":{}},{"cell_type":"code","source":"files , sr = librosa.load(filenames[29])\nprint(files)\nplt.plot(files)\n\nIPython.display.Audio(filenames[29])\n#TAR E AGOMON K kendro kore rochito gan e agomoni gan .\n# plain voice. No noise.","metadata":{"execution":{"iopub.status.busy":"2022-07-30T05:59:34.109995Z","iopub.execute_input":"2022-07-30T05:59:34.110519Z","iopub.status.idle":"2022-07-30T05:59:35.163845Z","shell.execute_reply.started":"2022-07-30T05:59:34.110487Z","shell.execute_reply":"2022-07-30T05:59:35.162371Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"files , sr = librosa.load(filenames[0])\nprint(files)\nplt.plot(files)\n\nIPython.display.Audio(filenames[0])\n#er moddhe odhikangso holen se somoyer hospital er mrito soinik ra \n# plain voice. No noise.","metadata":{"execution":{"iopub.status.busy":"2022-07-26T13:54:15.388338Z","iopub.execute_input":"2022-07-26T13:54:15.388740Z","iopub.status.idle":"2022-07-26T13:54:16.523724Z","shell.execute_reply.started":"2022-07-26T13:54:15.388707Z","shell.execute_reply":"2022-07-26T13:54:16.522559Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Calling a function for spectogram","metadata":{}},{"cell_type":"code","source":"def create_waveplot(data, sr, name):\n    plt.figure(figsize=(10, 3))\n    plt.title('Waveplot for audio of {} '.format(name), size=15)\n    librosa.display.waveplot(data, sr=sr)\n    plt.show()\n\ndef create_spectrogram(data, sr, name):\n    # stft function converts the data into short term fourier transform\n    X = librosa.stft(data)\n    Xdb = librosa.amplitude_to_db(abs(X))\n    plt.figure(figsize=(12, 3))\n    plt.title('Spectrogram for audio of {} '.format(name), size=15)\n    librosa.display.specshow(Xdb, sr=sr, x_axis='time', y_axis='hz')   \n    #librosa.display.specshow(Xdb, sr=sr, x_axis='time', y_axis='log')\n    plt.colorbar()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:32:58.105458Z","iopub.execute_input":"2022-07-30T20:32:58.105851Z","iopub.status.idle":"2022-07-30T20:32:58.114443Z","shell.execute_reply.started":"2022-07-30T20:32:58.105815Z","shell.execute_reply":"2022-07-30T20:32:58.113203Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Showing a spectogram ","metadata":{}},{"cell_type":"code","source":"name= 'tate gobeshona o biggan chorchar obadh sujog royeche '\nspectogram = []\nidx = 20\n#for idx in range(1000):\n\n\npath = filenames[idx]\ndata, sampling_rate = librosa.load(path)\n\na = create_spectrogram(data, sampling_rate, name)\n    #Audio(path)\nspectogram.append(a)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T20:33:00.872849Z","iopub.execute_input":"2022-07-30T20:33:00.873520Z","iopub.status.idle":"2022-07-30T20:33:01.875533Z","shell.execute_reply.started":"2022-07-30T20:33:00.873480Z","shell.execute_reply":"2022-07-30T20:33:01.874485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"name= 'tate gobeshona o biggan chorchar obadh sujog royeche '\nspectogram = []\nidx = 20\n#for idx in range(1000):\n\n\npath = filenames[idx]\ndata, sampling_rate = librosa.load(path)\n\na = create_spectrogram(data, sampling_rate, name)\n    #Audio(path)\nspectogram.append(a)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"\nname= 'obosorgrohoner por jadobpur bissobiddaloyer prodhan chilen sunil kumar shen.'\nspectogram = []\nidx = 20\n#for idx in range(1000):\n\n\npath = filenames[idx]\ndata, sampling_rate = librosa.load(path)\n\na = create_spectrogram(data, sampling_rate, name)\n    #Audio(path)\nspectogram.append(a)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The below code is a loop to show all 1000 spectogram \n","metadata":{}},{"cell_type":"code","source":" #(o,1000)\nfor i in range (0,5):  \n    spectogram = []\n    name = labels[i]\n\n    path = filenames[i]\n    data, sampling_rate = librosa.load(path)\n    name = librosa.load (path)\n    a = create_spectrogram(data, sampling_rate, name)\n    #Audio(path)\n    spectogram.append(a)","metadata":{"_kg_hide-output":true,"_kg_hide-input":true,"execution":{"iopub.status.busy":"2022-07-30T20:33:55.605059Z","iopub.execute_input":"2022-07-30T20:33:55.605438Z","iopub.status.idle":"2022-07-30T20:34:03.652626Z","shell.execute_reply.started":"2022-07-30T20:33:55.605405Z","shell.execute_reply":"2022-07-30T20:34:03.651611Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"**Data augmentation**","metadata":{}},{"cell_type":"markdown","source":"I took help here from a friend's notebook as I am not familiar with python.","metadata":{}},{"cell_type":"code","source":"To augment the data, we have to read the files using glob.  we are keeping it in wav_train_filepaths","metadata":{"execution":{"iopub.status.busy":"2022-07-30T21:40:59.044515Z","iopub.execute_input":"2022-07-30T21:40:59.045134Z","iopub.status.idle":"2022-07-30T21:40:59.058384Z","shell.execute_reply.started":"2022-07-30T21:40:59.045086Z","shell.execute_reply":"2022-07-30T21:40:59.056026Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"","metadata":{}},{"cell_type":"code","source":"wav_train_filepaths = glob('../input/wav-train-dlsprint-16000/wav_train_files/*.*')\n","metadata":{"execution":{"iopub.status.busy":"2022-07-30T21:41:04.450369Z","iopub.execute_input":"2022-07-30T21:41:04.450713Z","iopub.status.idle":"2022-07-30T21:41:09.461107Z","shell.execute_reply.started":"2022-07-30T21:41:04.450683Z","shell.execute_reply":"2022-07-30T21:41:09.460099Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Here we call a function for showing and plotting the audio","metadata":{}},{"cell_type":"code","source":"def load_audio_file(file_path):\n    input_length = 16000 # because the default sr of librosa is 16000\n    data = librosa.core.load(file_path)[0] \n    if len(data)>input_length:\n        data = data[:input_length]\n    else:\n        data = np.pad(data, (0, max(0, input_length - len(data))), \"constant\")\n    return data\ndef plot_time_series(data):\n    fig = plt.figure(figsize=(14, 8))\n    plt.title('Raw wave ')\n    plt.ylabel('Amplitude')\n    plt.plot(np.linspace(0, 1, len(data)), data)\n    plt.show()","metadata":{"execution":{"iopub.status.busy":"2022-07-30T21:41:13.013559Z","iopub.execute_input":"2022-07-30T21:41:13.013936Z","iopub.status.idle":"2022-07-30T21:41:13.022576Z","shell.execute_reply.started":"2022-07-30T21:41:13.013903Z","shell.execute_reply":"2022-07-30T21:41:13.021527Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":" Plotting Waveform and playing the file\n ","metadata":{}},{"cell_type":"code","source":"data = load_audio_file(\"../input/wav-train-dlsprint-16000/wav_train_files/common_voice_bn_30614365.wav\")\nplot_time_series(data)\n\nipd.Audio('../input/wav-train-dlsprint-16000/wav_train_files/common_voice_bn_30614365.wav')","metadata":{"execution":{"iopub.status.busy":"2022-07-30T21:41:15.968363Z","iopub.execute_input":"2022-07-30T21:41:15.968706Z","iopub.status.idle":"2022-07-30T21:41:16.453879Z","shell.execute_reply.started":"2022-07-30T21:41:15.968675Z","shell.execute_reply":"2022-07-30T21:41:16.452627Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"After augmentation, the audios will be as below: ","metadata":{}},{"cell_type":"markdown","source":"Getting the array of the audios using wavfile.read ","metadata":{}},{"cell_type":"code","source":"from scipy.io import wavfile\ndef wav_read(filename):\n \n    sampling_rate, wave = wavfile.read(filename)\n    \n    speech_array = np.float32(wave) \n    return speech_array,sampling_rate","metadata":{"execution":{"iopub.status.busy":"2022-07-30T21:41:20.172615Z","iopub.execute_input":"2022-07-30T21:41:20.173009Z","iopub.status.idle":"2022-07-30T21:41:20.178342Z","shell.execute_reply.started":"2022-07-30T21:41:20.172974Z","shell.execute_reply":"2022-07-30T21:41:20.177432Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The array of the audio:","metadata":{}},{"cell_type":"code","source":"wav_read('../input/wav-train-dlsprint-16000/wav_train_files/common_voice_bn_30614365.wav')","metadata":{"execution":{"iopub.status.busy":"2022-07-30T21:41:23.240248Z","iopub.execute_input":"2022-07-30T21:41:23.240594Z","iopub.status.idle":"2022-07-30T21:41:23.248642Z","shell.execute_reply.started":"2022-07-30T21:41:23.240562Z","shell.execute_reply":"2022-07-30T21:41:23.247756Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The real audio before augmentation","metadata":{}},{"cell_type":"code","source":"x = wav_read('../input/wav-train-dlsprint-16000/wav_train_files/common_voice_bn_30614365.wav')[0]\nprint(x)\nipd.Audio(x,rate=16000)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T21:41:25.526571Z","iopub.execute_input":"2022-07-30T21:41:25.527250Z","iopub.status.idle":"2022-07-30T21:41:25.542852Z","shell.execute_reply.started":"2022-07-30T21:41:25.527208Z","shell.execute_reply":"2022-07-30T21:41:25.541828Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"The white noise","metadata":{}},{"cell_type":"code","source":"# The  white noise \nwn = np.random.randn(len(data))\ndata_wn = data + 0.005*wn\nplot_time_series(data_wn)\n# We limited the amplitude of the noise so we can still hear the word even with the noise, \n#which is the objective\nipd.Audio(data_wn, rate=16000)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T21:41:28.515656Z","iopub.execute_input":"2022-07-30T21:41:28.516315Z","iopub.status.idle":"2022-07-30T21:41:28.754735Z","shell.execute_reply.started":"2022-07-30T21:41:28.516278Z","shell.execute_reply":"2022-07-30T21:41:28.753846Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Calling a function for adding white noise\n","metadata":{}},{"cell_type":"code","source":"# Adding white noise\ndef add_white_noise(filepath,noise_factor):\n    \n    data = wav_read(filepath)[0]\n    wn = np.random.randn(len(data))\n    data_wn = data + noise_factor*wn   #noise factor=0 hole kono noise add hocchena. joto barabo toto beshi noise add hone\n    \n   \n \n    \n    return data_wn\n    ","metadata":{"execution":{"iopub.status.busy":"2022-07-30T21:41:35.901272Z","iopub.execute_input":"2022-07-30T21:41:35.901948Z","iopub.status.idle":"2022-07-30T21:41:35.907415Z","shell.execute_reply.started":"2022-07-30T21:41:35.901912Z","shell.execute_reply":"2022-07-30T21:41:35.906459Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"after adding white noise","metadata":{}},{"cell_type":"code","source":"# #after adding white noise\nfile_path='../input/wav-train-dlsprint-16000/wav_train_files/common_voice_bn_30614365.wav'\ny=add_white_noise(file_path,noise_factor=10)\nprint(y)\nipd.Audio(y,rate=16000)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T21:41:38.018379Z","iopub.execute_input":"2022-07-30T21:41:38.018724Z","iopub.status.idle":"2022-07-30T21:41:38.038059Z","shell.execute_reply.started":"2022-07-30T21:41:38.018693Z","shell.execute_reply":"2022-07-30T21:41:38.037151Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Shifting command and visualising the shifting","metadata":{}},{"cell_type":"code","source":"# Shifting the sound\ndata_roll = np.roll(data, 1600)\nplot_time_series(data_roll)\nipd.Audio(data_roll, rate=16000)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T21:41:41.092185Z","iopub.execute_input":"2022-07-30T21:41:41.093233Z","iopub.status.idle":"2022-07-30T21:41:41.308557Z","shell.execute_reply.started":"2022-07-30T21:41:41.093182Z","shell.execute_reply":"2022-07-30T21:41:41.307688Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Function for shifting Audio","metadata":{}},{"cell_type":"code","source":"# Shifting the sound\ndef shift_sound(filepath):\n    data = wav_read(filepath)[0]\n    data_roll = np.roll(data, 1600)\n    return data_roll\n   ","metadata":{"execution":{"iopub.status.busy":"2022-07-30T21:41:44.779759Z","iopub.execute_input":"2022-07-30T21:41:44.780419Z","iopub.status.idle":"2022-07-30T21:41:44.785907Z","shell.execute_reply.started":"2022-07-30T21:41:44.780381Z","shell.execute_reply":"2022-07-30T21:41:44.784897Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"After shifting data","metadata":{}},{"cell_type":"code","source":"# after Shifting\nfile_path=('../input/wav-train-dlsprint-16000/wav_train_files/common_voice_bn_30614365.wav')\ny=shift_sound(file_path)\nprint(y)\nipd.Audio(y,rate=16000)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T21:41:47.171277Z","iopub.execute_input":"2022-07-30T21:41:47.172233Z","iopub.status.idle":"2022-07-30T21:41:47.187739Z","shell.execute_reply.started":"2022-07-30T21:41:47.172194Z","shell.execute_reply":"2022-07-30T21:41:47.186690Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Calling a function for streching","metadata":{}},{"cell_type":"code","source":"def time_stretch(filepath, stretch_rate):\n    data = wav_read(filepath)[0]\n    \n    data = librosa.effects.time_stretch(data, stretch_rate)\n    \n    return data","metadata":{"execution":{"iopub.status.busy":"2022-07-30T21:41:52.501172Z","iopub.execute_input":"2022-07-30T21:41:52.502231Z","iopub.status.idle":"2022-07-30T21:41:52.507264Z","shell.execute_reply.started":"2022-07-30T21:41:52.502179Z","shell.execute_reply":"2022-07-30T21:41:52.506311Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Audio after strech","metadata":{}},{"cell_type":"code","source":"\n#after time stretch\ny=time_stretch(file_path,0.75)\nipd.Audio(y,rate=16000)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T21:41:55.266453Z","iopub.execute_input":"2022-07-30T21:41:55.267402Z","iopub.status.idle":"2022-07-30T21:41:55.729525Z","shell.execute_reply.started":"2022-07-30T21:41:55.267365Z","shell.execute_reply":"2022-07-30T21:41:55.728649Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Loop for augmenting all data","metadata":{}},{"cell_type":"code","source":"audio_with_noise = []\nfor i in range (0,10):\n    \n   \n\n    data = wav_train_filepaths[i]\n    a = add_white_noise(data,noise_factor=0.5)\n    audio_with_noise.append(a)\n  \n     \n    ","metadata":{"execution":{"iopub.status.busy":"2022-07-30T22:32:17.839159Z","iopub.execute_input":"2022-07-30T22:32:17.839509Z","iopub.status.idle":"2022-07-30T22:32:17.882905Z","shell.execute_reply.started":"2022-07-30T22:32:17.839480Z","shell.execute_reply":"2022-07-30T22:32:17.881958Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range (0,10):\n    \n    audio_with_stretch = []\n\n    data = wav_train_filepaths[i]\n    b = time_stretch(data,stretch_rate=0.9)\n   \n    \n    audio_with_stretch.append(b)\n    ","metadata":{"execution":{"iopub.status.busy":"2022-07-30T22:27:19.428026Z","iopub.execute_input":"2022-07-30T22:27:19.428375Z","iopub.status.idle":"2022-07-30T22:27:19.989966Z","shell.execute_reply.started":"2022-07-30T22:27:19.428345Z","shell.execute_reply":"2022-07-30T22:27:19.988959Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for i in range (0,10):\n    \n    shifted_audio = []\n    data = wav_train_filepaths[i]\n    c= shift_sound(data)\n    shifted_audio.append(c)","metadata":{"execution":{"iopub.status.busy":"2022-07-30T22:27:14.042497Z","iopub.execute_input":"2022-07-30T22:27:14.042879Z","iopub.status.idle":"2022-07-30T22:27:14.060469Z","shell.execute_reply.started":"2022-07-30T22:27:14.042845Z","shell.execute_reply":"2022-07-30T22:27:14.059561Z"},"trusted":true},"execution_count":null,"outputs":[]}]}