{"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":"markdown","source":"# In this code for the moment i only search a way to manage the data","metadata":{}},{"cell_type":"code","source":"#Note: A lot of times i use 2 to say \"to\"\n\nimport pandas as pd  #Import Pandas\nimport numpy as np  #Import NumPy\nimport matplotlib.pylab as plt  #Import matplotlib\nimport seaborn as sns  #Python data visualization library\n\nimport random #2 make a random numer\n\nfrom glob import glob #2 List the files in a directory\n\nimport librosa  #Python package for music and audio analysis\nimport librosa.display  #Python package for music and audio analysis\nimport IPython.display as ipd  #2 Display audio samples\n\n#For Aesthetics to plots \nfrom itertools import cycle\n\nsns.set_theme(style=\"white\", palette=None)\ncolor_pal = plt.rcParams[\"axes.prop_cycle\"].by_key()[\"color\"]\ncolor_cycle = cycle(plt.rcParams[\"axes.prop_cycle\"].by_key()[\"color\"])\n#For Aesthetics to plots","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-03-17T20:11:21.651675Z","iopub.execute_input":"2022-03-17T20:11:21.652547Z","iopub.status.idle":"2022-03-17T20:11:24.018307Z","shell.execute_reply.started":"2022-03-17T20:11:21.652505Z","shell.execute_reply":"2022-03-17T20:11:24.017244Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_sng = pd.read_csv('../input/kaggle-pog-series-s01e02/train.csv') #Read csv\ngenres = pd.read_csv('../input/kaggle-pog-series-s01e02/genres.csv') #Read csv\ndata_train ='../input/kaggle-pog-series-s01e02/train/' #Data of the songs 2 train\ndata_test ='../input/kaggle-pog-series-s01e02/test/' #Data of the songs 2 test\n#Delet the \"#\" in the next lines if you want see the DataFrame\n#print(genres) #Print the list of the genre\n#print('')\n#print(train_sng)  #Print the csv","metadata":{"execution":{"iopub.status.busy":"2022-03-17T20:11:24.020455Z","iopub.execute_input":"2022-03-17T20:11:24.020792Z","iopub.status.idle":"2022-03-17T20:11:24.130536Z","shell.execute_reply.started":"2022-03-17T20:11:24.020749Z","shell.execute_reply":"2022-03-17T20:11:24.129578Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sngs_gen = []\n\nfor x in genres['genre_id']:\n    train_sng_temp = train_sng.loc[train_sng['genre_id'] == x] #Search in the column \"genre_id\" the rows with the same gender\n    #train_sng_temp = train_sng_temp[['filepath']]\n    sngs_gen.append(train_sng_temp) #Append those songs in anohter list","metadata":{"execution":{"iopub.status.busy":"2022-03-17T20:11:24.131782Z","iopub.execute_input":"2022-03-17T20:11:24.132076Z","iopub.status.idle":"2022-03-17T20:11:24.155369Z","shell.execute_reply.started":"2022-03-17T20:11:24.132036Z","shell.execute_reply":"2022-03-17T20:11:24.154630Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#Now you can chane the value in the list to see all the songs with the same gender\nsngs_gen[14]","metadata":{"execution":{"iopub.status.busy":"2022-03-17T20:38:35.421366Z","iopub.execute_input":"2022-03-17T20:38:35.421915Z","iopub.status.idle":"2022-03-17T20:38:35.437244Z","shell.execute_reply.started":"2022-03-17T20:38:35.421878Z","shell.execute_reply":"2022-03-17T20:38:35.436540Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#This code is only to count the numers of row in a list\nsngs_gen[5][sngs_gen[0].columns[0]].count()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T20:11:24.180515Z","iopub.execute_input":"2022-03-17T20:11:24.181163Z","iopub.status.idle":"2022-03-17T20:11:24.185869Z","shell.execute_reply.started":"2022-03-17T20:11:24.181130Z","shell.execute_reply":"2022-03-17T20:11:24.185293Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#This code line is 2 obtain the information of a certain row, in this case the name of the file\nsngs_gen[13].iat[4,1]","metadata":{"execution":{"iopub.status.busy":"2022-03-17T20:11:24.186780Z","iopub.execute_input":"2022-03-17T20:11:24.187576Z","iopub.status.idle":"2022-03-17T20:11:24.205311Z","shell.execute_reply.started":"2022-03-17T20:11:24.187466Z","shell.execute_reply":"2022-03-17T20:11:24.204318Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Play an example of audio file, you can chane the gender in the first \"[]\" and you can change the song in the first numer of the second \"[]\"\nipd.Audio(data_train + str(sngs_gen[11].iat[7,1]))","metadata":{"execution":{"iopub.status.busy":"2022-03-17T20:11:24.206586Z","iopub.execute_input":"2022-03-17T20:11:24.206801Z","iopub.status.idle":"2022-03-17T20:11:24.249783Z","shell.execute_reply.started":"2022-03-17T20:11:24.206775Z","shell.execute_reply":"2022-03-17T20:11:24.248878Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"plt.figure(figsize=(10, 5))\n\nfor x in range(1,6):\n    \n    gndr_randm_num = random.randint(0, (genres[genres.columns[1]].count()) -1 ) #Generate a random number in range of the numers of genders \n    sng_randm_num = random.randint(0, (sngs_gen[gndr_randm_num][sngs_gen[0].columns[0]].count() -1 )) #Generate a random number in range of the numers of songs in this gender    \n    \n    y, sr = librosa.load(data_train + sngs_gen[gndr_randm_num].iat[sng_randm_num,1]) #Obtain the song \n    \n    \n    pd.Series(y).plot(lw=6,\n                      title='Raw Audio Example with of ' + \n                      str((genres.loc[genres['genre_id'] == gndr_randm_num]).iat[0,0]) + ' in the song ' +  #Search the name of the gender in the list\n                      sngs_gen[gndr_randm_num].iat[sng_randm_num,1],\n                      subplots= x, \n                      color=color_pal[0])\n    \n    plt.show()\n    \n\n    #Ignore this\n    #for x in range(sngs_gen[x][sngs_gen[0].columns[0]].count()):\n    #for x in range(sngs_gen[18][sngs_gen[0].columns[0]].count()):\n    #    print(x)","metadata":{"execution":{"iopub.status.busy":"2022-03-17T21:04:10.970778Z","iopub.execute_input":"2022-03-17T21:04:10.971607Z","iopub.status.idle":"2022-03-17T21:04:19.565658Z","shell.execute_reply.started":"2022-03-17T21:04:10.971557Z","shell.execute_reply":"2022-03-17T21:04:19.564705Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#If you want, you can search the song of the previous celd you can do it with the next code only change the numer of the song and the gender in the both \"[]\"\nsngs_gen[16].loc[sngs_gen[16]['filename'] == '010812.ogg' ]","metadata":{"execution":{"iopub.status.busy":"2022-03-17T20:44:02.660350Z","iopub.execute_input":"2022-03-17T20:44:02.660829Z","iopub.status.idle":"2022-03-17T20:44:02.670852Z","shell.execute_reply.started":"2022-03-17T20:44:02.660793Z","shell.execute_reply":"2022-03-17T20:44:02.670306Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# **Below thre are only notes and experiments**","metadata":{}},{"cell_type":"code","source":"y, sr = librosa.load(data_train + sngs_gen[0].iat[4,1])\nprint(y)","metadata":{"execution":{"iopub.status.busy":"2022-03-17T20:35:46.829428Z","iopub.execute_input":"2022-03-17T20:35:46.829702Z","iopub.status.idle":"2022-03-17T20:35:48.180509Z","shell.execute_reply.started":"2022-03-17T20:35:46.829673Z","shell.execute_reply":"2022-03-17T20:35:48.179597Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"pd.Series(y).plot(figsize=(6, 3),\n                  lw=1,\n                  title='Raw Audio Example',\n                 color=color_pal[0])\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T17:56:24.247222Z","iopub.execute_input":"2022-03-17T17:56:24.247507Z","iopub.status.idle":"2022-03-17T17:56:24.630845Z","shell.execute_reply.started":"2022-03-17T17:56:24.247478Z","shell.execute_reply":"2022-03-17T17:56:24.629843Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"D = librosa.stft(y)\nS_db = librosa.amplitude_to_db(np.abs(D), ref=np.max)\nS_db.shape","metadata":{"execution":{"iopub.status.busy":"2022-03-17T17:52:19.926696Z","iopub.execute_input":"2022-03-17T17:52:19.928146Z","iopub.status.idle":"2022-03-17T17:52:20.030108Z","shell.execute_reply.started":"2022-03-17T17:52:19.928066Z","shell.execute_reply":"2022-03-17T17:52:20.029051Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"# Plot the transformed audio data\nfig, ax = plt.subplots(figsize=(10, 5))\nimg = librosa.display.specshow(S_db,\n                              x_axis='time',\n                              y_axis='log',\n                              ax=ax)\nax.set_title('Spectogram Example', fontsize=20)\nfig.colorbar(img, ax=ax, format=f'%0.2f')\nplt.show()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T17:52:20.781896Z","iopub.execute_input":"2022-03-17T17:52:20.782207Z","iopub.status.idle":"2022-03-17T17:52:22.059071Z","shell.execute_reply.started":"2022-03-17T17:52:20.782176Z","shell.execute_reply":"2022-03-17T17:52:22.058396Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print(genres[genres.columns[1]].count())","metadata":{"execution":{"iopub.status.busy":"2022-03-17T19:14:46.614574Z","iopub.execute_input":"2022-03-17T19:14:46.61502Z","iopub.status.idle":"2022-03-17T19:14:46.620852Z","shell.execute_reply.started":"2022-03-17T19:14:46.614983Z","shell.execute_reply":"2022-03-17T19:14:46.620054Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sngs_gen[0].iat[0,1]","metadata":{"execution":{"iopub.status.busy":"2022-03-17T20:31:26.844522Z","iopub.execute_input":"2022-03-17T20:31:26.844828Z","iopub.status.idle":"2022-03-17T20:31:26.849883Z","shell.execute_reply.started":"2022-03-17T20:31:26.844790Z","shell.execute_reply":"2022-03-17T20:31:26.849352Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sngs_gen[18][sngs_gen[0].columns[0]].count()","metadata":{"execution":{"iopub.status.busy":"2022-03-17T20:26:37.349534Z","iopub.execute_input":"2022-03-17T20:26:37.350065Z","iopub.status.idle":"2022-03-17T20:26:37.355281Z","shell.execute_reply.started":"2022-03-17T20:26:37.350029Z","shell.execute_reply":"2022-03-17T20:26:37.354668Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sngs_gen[14].loc[sngs_gen[14]['filename'] == '005867.ogg' ]\n","metadata":{"execution":{"iopub.status.busy":"2022-03-17T20:40:12.987617Z","iopub.execute_input":"2022-03-17T20:40:12.988467Z","iopub.status.idle":"2022-03-17T20:40:12.999948Z","shell.execute_reply.started":"2022-03-17T20:40:12.988417Z","shell.execute_reply":"2022-03-17T20:40:12.999148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"for x in range(1,11):\n    print(x)","metadata":{"execution":{"iopub.status.busy":"2022-03-17T20:50:49.353828Z","iopub.execute_input":"2022-03-17T20:50:49.354141Z","iopub.status.idle":"2022-03-17T20:50:49.359610Z","shell.execute_reply.started":"2022-03-17T20:50:49.354102Z","shell.execute_reply":"2022-03-17T20:50:49.358531Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}