{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"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 in \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 \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nimport os\nimport tensorflow as tf\nimport pickle\nimport librosa","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"classes = os.listdir(\"../input/train/audio/\")\nprint(classes)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"080e796709cd278282b15544557cc152ff7bbe50"},"cell_type":"code","source":"def create_data():\n    x = []\n    y = []\n    for c in classes:\n        try:\n            tmpx = []\n            tmpy = []\n            print('processs-...', c)\n\n            for file in os.listdir('../input/train/audio/' + c):\n                wave,sr = librosa.load('../input/train/audio/' + c +'/' + file, mono=True)\n                mfcc = librosa.feature.mfcc(y=wave, sr=sr, n_mfcc=20)\n                if mfcc.shape == (20, 44):\n                    x.append(mfcc)\n                    tmpx.append(mfcc)\n                    y.append(classes.index(c))\n                    tmpy.append(classes.index(c))\n\n            print('write file pickle ', c)\n            pickle.dump(np.array(tmpx), open('{}.pickle'.format(c), 'wb'))\n            pickle.dump(np.array(tmpy), open('{}_y.pickle'.format(c), 'wb'))\n        except:\n            pass\n            \n\n    print('complete')\n    return np.array(x), np.array(y)\n        ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c81651e6420d6e41ebb074360b8db91692581acc"},"cell_type":"code","source":"x, y = create_data()\n        ","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e3063f4e6c479b6de727bdbbfdf843c92be4064a"},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"857da56a8d4f40f942358a36f4c8af2ef1321301"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}