{"cells":[{"metadata":{},"cell_type":"markdown","source":"Notebook contains simple examples for checking the [dataset](https://www.kaggle.com/sapr3s/timestamps-for-train-data-cornell-birdcall)","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"I have limited the duration of the audio files I create, otherwise they are too big . To check the full file, change: limit = False","execution_count":null},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport IPython.display as ipd\nimport librosa\nimport warnings\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"warnings.filterwarnings('ignore')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"input_path = '../input/birdsong-recognition/'\ndataset_path = '../input/timestamps-for-train-data-cornell-birdcall/'\n","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"sr = 32000\npause_sec = 0.2\nlimit = True\nlimit_sec = 60","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"def get_aud_bird(df_full, bird, pause_sec):\n    pause = np.zeros(int(pause_sec * sr))\n    aud = pause\n\n    df = df_full[df_full['bird']==bird]\n    files = df['file'].unique()\n    print(f'{bird} - {len(files)} files {len(df)} samples')\n    \n    for file in files:\n        if limit:\n            if len(aud) > limit_sec * sr:\n                break\n        aud_file , _ = librosa.load(f'{input_path}train_audio/{bird}/{file}', mono=True, sr=sr)\n        aud_file = librosa.util.normalize(aud_file, axis=0)\n        df_file = df[df['file']==file]\n        for i, r in df_file.iterrows():\n            start = int(r['start'] * sr)\n            end = start + int(r['duration'] * sr)\n            aud = np.concatenate((aud, aud_file[start:end], pause)) \n    \n    return aud","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"df = pd.read_csv(f'{dataset_path}timestamps-train-cornell-birds.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"aud = get_aud_bird(df, 'aldfly', pause_sec)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"ipd.Audio(aud, rate=sr)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"Awesome **normoc**\n\nIt turned out almost an hour of marked sounds. It can represent other birds. I think it needs a separate classifier. This reminds me of the struggle 'generator vs discriminator' in the GAN","execution_count":null},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"aud_normoc = get_aud_bird(df, 'normoc', pause_sec)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"ipd.Audio(aud_normoc, rate=sr)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**norcar**\n\nNow I understand where the car alarm sound came from :)","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"aud_norcar = get_aud_bird(df, 'norcar', pause_sec)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"ipd.Audio(aud_norcar, rate=sr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}