{"cells":[{"metadata":{},"cell_type":"markdown","source":"<h1 style=\"text-align:center;font-size:46px\">Cornell Birdcall Identification EDA</h1>\n\n<a href=\"https://imgbb.com/\"><img src=\"https://i.ibb.co/5Y96jpx/What-the-BIRD.png\" alt=\"What-the-BIRD\"></a>","execution_count":null},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"import numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\nimport matplotlib.pyplot as plt\nimport seaborn as sns\n\nimport torch\nimport torchaudio\nimport matplotlib.pyplot as plt\n\nimport IPython.display as ipd\n\n\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\nfrom os import path\n\n\n\n%matplotlib inline","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"!pip install tinytag","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"DATA_PATH = '../input/birdsong-recognition/'\nAUDIO_PATH = \"../input/birdsong-recognition/train_audio\"","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<div style=\"display:flex\">\n    <div>\n        <a href=\"https://ebird.org/species/aldfly\"><img src=\"https://i.ibb.co/9VJTLsC/160820341.jpg\" alt=\"160820341\" border=\"0\" width=400px></a>\n    </div>\n    <div style=\"margin-left:20px\">\n        <h1>Aldfly</h1>\n        <h2>Description</h2>\n        <p style=\"width:500px; font-size:14px\">Small flycatcher, extremely similar to several other species. Prefers clearings and boggy areas, often with patches of alders. Grayish-olive above and pale below with thin white eyering. Wings dark with bold white wingbars. Nearly identical to Willow Flycatcher; once considered the same species. Also compare with Least Flycatcher, which is very similar but has slightly shorter wingtips and a bolder eyering. Best identified by voice: song is a rolling, rough \"freeBEER;\" call is a clear \"pip.\" Silent birds, especially in migration, often best left unidentified.</p>\n    </div>\n</div>\n","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"display(ipd.Audio('../input/birdsong-recognition/train_audio/aldfly/XC134874.mp3'))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<div style=\"display:flex\">\n    <div>\n         <a href=\"https://ebird.org/species/Ameavo\"><img src=\"https://i.ibb.co/HzgXmcK/64807071.jpg\" alt=\"64807071\" border=\"0\" width=400px></a>\n    </div>\n    <div style=\"margin-left:20px\">\n        <h1>Ameavo</h1>\n        <h2>Description</h2>\n        <p style=\"width:500px; font-size:14px\">Distinctive large shorebird with a long, thin upturned bill and lean neck. Bold black-and-white wings prominent year-round. Adults in summer have buffy-orange wash on head. Frequents wetlands where it swings its head back-and-forth in shallow water to catch small invertebrates.</p>\n    </div>\n</div>","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"display(ipd.Audio('../input/birdsong-recognition/train_audio/ameavo/XC133080.mp3'))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<div style=\"display:flex\">\n    <div>\n       <a href=\"https://ebird.org/species/Amebit\"><img src=\"https://i.ibb.co/m86C9nq/37758621.jpg\" alt=\"37758621\" border=\"0\" width=400px></a> \n    </div>\n    <div style=\"margin-left:20px\">\n        <h1>Amebit</h1>\n        <h2>Description</h2>\n        <p style=\"width:500px; font-size:14px\">Stocky, brown heron found in marshes and bogs; secretive but occasionally found in the open. Most similar to juvenile night-herons. Note striped neck, plain unspotted wings, and behavior: American Bittern does not typically perch on branches. Varied diet includes fish, frogs, insects, and small mammals. Most active around dawn and dusk flying low over extensive marshes. Listen for its incredible vocalization: a resonant, booming noise produced by air sacs on the neck, \"oonk-GA-loonk.</p>\n    </div>\n</div>","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"display(ipd.Audio('../input/birdsong-recognition/train_audio/amebit/XC127371.mp3'))","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"df_train = pd.read_csv(DATA_PATH + 'train.csv')","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<h1>Explore train data</h1>","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"df_train.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<h2>Visualization of \"ebird_code\"</h2>","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"species_count = df_train['ebird_code'].value_counts(sort=True)\nspecies_count = species_count[250:]\nplt.figure(figsize=(15,7))\nsns.barplot(species_count.index,species_count.values,palette=(\"Blues_d\"), alpha=0.85)\nplt.title('Birds species distribution', fontsize=18)\nplt.ylabel('Number of Occurrences', fontsize=12)\nplt.xlabel('Birds code', fontsize=12)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"print('Minimum samples per category = ', min(df_train.ebird_code.value_counts()))\nprint('Maximum samples per category = ', max(df_train.ebird_code.value_counts()))","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"print(\"Total number of labels: \",len(df_train['ebird_code'].value_counts()))\nprint(\"Labels: \", df_train['ebird_code'].unique())","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<h3>Word cloud viz for ebird_code</h3>","execution_count":null},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"from wordcloud import WordCloud\nwordcloud = WordCloud(background_color=\"white\", max_font_size=50, width=800, height=500, collocations=False, max_words=200).generate(' '.join(df_train['ebird_code']))\nplt.figure(figsize=(18,10))\nplt.imshow(wordcloud, cmap=plt.cm.gray)\nplt.title(\"Wordcloud for Labels in Train Curated\", fontsize=25)\nplt.axis(\"off\")\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<hr>","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"<h3>Visualization of \"playback_used\"</h3>","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"playback_used_count  = df_train['playback_used'].value_counts(sort=True)\nplayback_used_count = playback_used_count[:10]\nplt.figure(figsize=(15,7))\nsns.barplot(playback_used_count.index,playback_used_count.values,palette=(\"Blues_d\"), alpha=0.85)\nplt.title('Playback_used distribution', fontsize=18)\nplt.ylabel('Number of Occurrences', fontsize=12)\nplt.xlabel('Playback_used', fontsize=12)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"print('Minimum samples per category = ', min(df_train.playback_used.value_counts()))\nprint('Maximum samples per category = ', max(df_train.playback_used.value_counts()))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<hr>","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"<h3>Visualization of \"channels\"</h3>","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"channels_count  = df_train['channels'].value_counts(sort=True)\nchannels_count = channels_count[:10]\nplt.figure(figsize=(15,7))\nsns.barplot(channels_count.index,channels_count.values,palette=(\"Blues_d\"), alpha=0.85)\nplt.title('Channels distribution', fontsize=18)\nplt.ylabel('Number of Occurrences', fontsize=12)\nplt.xlabel('Channels', fontsize=12)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"print('Minimum samples per category = ', min(df_train.channels.value_counts()))\nprint('Maximum samples per category = ', max(df_train.channels.value_counts()))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<hr>","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"<h3>Visualization of \"date\"</h3>","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"date_count  = df_train['date'].value_counts(sort=True)\ndate_count = date_count[:10]\nplt.figure(figsize=(15,7))\nsns.barplot(date_count.index,date_count.values,palette=(\"Blues_d\"), alpha=0.85)\nplt.title('Date distribution', fontsize=18)\nplt.ylabel('Number of Occurrences', fontsize=12)\nplt.xlabel('Date', fontsize=12)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"print('Minimum samples per category = ', min(df_train.date.value_counts()))\nprint('Maximum samples per category = ', max(df_train.date.value_counts()))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<hr>","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"<h3>Visualization of \"pitch\"</h3>","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"pitch_count  = df_train['pitch'].value_counts(sort=True)\npitch_count = pitch_count[:10]\nplt.figure(figsize=(15,7))\nsns.barplot(pitch_count.index,pitch_count.values,palette=(\"Blues_d\"), alpha=0.85)\nplt.title('Pitch distribution', fontsize=18)\nplt.ylabel('Number of Occurrences', fontsize=12)\nplt.xlabel('Pitch', fontsize=12)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"print('Minimum samples per category = ', min(df_train.pitch.value_counts()))\nprint('Maximum samples per category = ', max(df_train.pitch.value_counts()))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<hr>","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"<h3>Visualization of \"duration\"</h3>","execution_count":null},{"metadata":{"_kg_hide-input":true,"trusted":true},"cell_type":"code","source":"duration_count  = df_train['duration'].value_counts(sort=True)\nduration_count = duration_count[:30]\nplt.figure(figsize=(15,7))\nsns.barplot(duration_count.index,duration_count.values,palette=(\"Blues_d\"), alpha=0.85)\nplt.title('Duration distribution', fontsize=18)\nplt.ylabel('Number of Occurrences', fontsize=12)\nplt.xlabel('Duration', fontsize=12)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"print('Minimum samples per category = ', min(df_train.duration.value_counts()))\nprint('Maximum samples per category = ', max(df_train.duration.value_counts()))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<hr>","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"<h3>Visualization of \"speed\"</h3>","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"speed_count  = df_train['speed'].value_counts(sort=True)\nspeed_count = speed_count[:10]\nplt.figure(figsize=(15,7))\nsns.barplot(speed_count.index,speed_count.values,palette=(\"Blues_d\"), alpha=0.85)\nplt.title('Speed distribution', fontsize=18)\nplt.ylabel('Number of Occurrences', fontsize=12)\nplt.xlabel('Speed', fontsize=12)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"print('Minimum samples per category = ', min(df_train.speed.value_counts()))\nprint('Maximum samples per category = ', max(df_train.speed.value_counts()))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<hr>","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"<h3>Visualization of \"type\"</h3>","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"type_count  = df_train['type'].value_counts(sort=True)\ntype_count = type_count[:10]\nplt.figure(figsize=(15,7))\nsns.barplot(type_count.index,type_count.values,palette=(\"Blues_d\"), alpha=0.85)\nplt.title('Type distribution', fontsize=18)\nplt.ylabel('Number of Occurrences', fontsize=12)\nplt.xlabel('Type', fontsize=12)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"print('Minimum samples per category = ', min(df_train.type.value_counts()))\nprint('Maximum samples per category = ', max(df_train.type.value_counts()))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<hr>","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"<h3>Visualization of \"sampling_rate\"</h3>","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"sampling_rate_count  = df_train['sampling_rate'].value_counts(sort=True)\nplt.figure(figsize=(15,7))\nsns.barplot(sampling_rate_count.index,sampling_rate_count.values,palette=(\"Blues_d\"), alpha=0.85)\nplt.title('Sampling rate distribution', fontsize=18)\nplt.ylabel('Number of Occurrences', fontsize=12)\nplt.xlabel('Rate (Hz)', fontsize=12)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"print('Minimum samples per category = ', min(df_train.sampling_rate.value_counts()))\nprint('Maximum samples per category = ', max(df_train.sampling_rate.value_counts()))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<hr>","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"<h3>Visualization of \"elevation\"</h3>","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"elevation_count  = df_train['elevation'].value_counts(sort=True)\nelevation_count = elevation_count[:10]\nplt.figure(figsize=(15,7))\nsns.barplot(elevation_count.index,elevation_count.values,palette=(\"Blues_d\"), alpha=0.85)\nplt.title('Elevation distribution', fontsize=18)\nplt.ylabel('Number of Occurrences', fontsize=12)\nplt.xlabel('Elevation', fontsize=12)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"print('Minimum samples per category = ', min(df_train.elevation.value_counts()))\nprint('Maximum samples per category = ', max(df_train.elevation.value_counts()))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<hr>","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"<h3>Visualization of \"bitrate_of_mp3\"</h3>","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"bitrate_of_mp3_count  = df_train['bitrate_of_mp3'].value_counts(sort=True)\nbitrate_of_mp3_count = bitrate_of_mp3_count[:10]\nplt.figure(figsize=(15,7))\nsns.barplot(bitrate_of_mp3_count.index,bitrate_of_mp3_count.values,palette=(\"Blues_d\"), alpha=0.85)\nplt.title('Bitrate_of_mp3 distribution', fontsize=18)\nplt.ylabel('Number of Occurrences', fontsize=12)\nplt.xlabel('Bitrate_of_mp3', fontsize=12)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"print('Minimum samples per category = ', min(df_train.bitrate_of_mp3.value_counts()))\nprint('Maximum samples per category = ', max(df_train.bitrate_of_mp3.value_counts()))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<hr>","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"<h3>Visualization of \"country\"</h3>","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"country_count  = df_train['country'].value_counts(sort=True)\ncountry_count = country_count[:10]\nplt.figure(figsize=(15,7))\nsns.barplot(country_count.index,country_count.values,palette=(\"Blues_d\"), alpha=0.85)\nplt.title('Countries distribution', fontsize=18)\nplt.ylabel('Number of Occurrences', fontsize=12)\nplt.xlabel('Country', fontsize=12)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"print('Minimum samples per category = ', min(df_train.country.value_counts()))\nprint('Maximum samples per category = ', max(df_train.country.value_counts()))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<hr>\n","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"<h3>Visualization of \"recordist\"</h3>","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"recordist_count  = df_train['recordist'].value_counts(sort=True)\nrecordist_count = recordist_count[:10]\nplt.figure(figsize=(15,7))\nsns.barplot(recordist_count.index,recordist_count.values,palette=(\"Blues_d\"), alpha=0.85)\nplt.title('Recordists distribution', fontsize=18)\nplt.ylabel('Number of Occurrences', fontsize=12)\nplt.xlabel('Recordists', fontsize=12)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"print('Minimum samples per category = ', min(df_train.recordist.value_counts()))\nprint('Maximum samples per category = ', max(df_train.recordist.value_counts()))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<hr>","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"<h1>Checking other files</h1>","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"**Let's check what is in 'test.csv'**","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"df_test = pd.read_csv(DATA_PATH + 'test.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"df_test.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Just have to have a look what is inside \"example_test_audio_summary.csv\"**","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"ex_test_summary = pd.read_csv(DATA_PATH + 'example_test_audio_summary.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"ex_test_summary.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Just have to have a look what is inside \"example_test_audio_metadata.csv\"**","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"ex_test_meta = pd.read_csv(DATA_PATH + 'example_test_audio_metadata.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"ex_test_meta.head()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"**Let's count check folders and files structure**\n","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"files = folders = 0\nFolderList = []\nfor _, dirnames, filenames in os.walk(AUDIO_PATH):\n    files += len(filenames)\n    folders += len(dirnames)\n    FolderList.append(dirnames)\n        \nprint(\"There are {:,} files, and {:,} folders\".format(files, folders))","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<h3>Extracting metadata straight from the file</h3>","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"File from \"aldfly/XC134874.mp3\" as an example","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"from tinytag import TinyTag","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"tag = TinyTag.get(AUDIO_PATH + \"/aldfly/XC134874.mp3\", image=True)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"print('album:',tag.album)\nprint('album artist:',tag.albumartist) # album artist\nprint('artist name:',tag.artist)       # artist name\nprint('number of bytes before audio data begins:',tag.audio_offset)  # number of bytes before audio data begins\nprint('bitrate in kBits/s:',tag.bitrate) # bitrate in kBits/s\nprint('file comment', tag.comment)     # file comment\nprint('composer', tag.composer)        # composer\nprint('disc number', tag.disc)         # disc number\nprint('total number of discs',tag.disc_total)    # total number of discs\nprint('duration of the song in seconds', tag.duration)      # duration of the song in seconds\nprint('file size in bytes', tag.filesize)      # file size in bytes\nprint('genre', tag.genre)              # genre\nprint('samples per second', tag.samplerate)    # samples per second\nprint('title of the song', tag.title)  # title of the song\nprint('track number', tag.track)       # track number\nprint('total number of tracks', tag.track_total)     # total number of tracks\nprint('year or data', tag.year)        # year or data","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<h1>Plotting spectrograms</h1> ","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true,"_kg_hide-output":true},"cell_type":"code","source":"from IPython.display import Audio\nfrom matplotlib import pyplot as plt\nimport torchaudio\nimport torch\n\nimport librosa\nimport librosa.display","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<h3>Compare time of plotting with librosa and torchaudio</h3>","execution_count":null},{"metadata":{},"cell_type":"markdown","source":"<h3>Torchaudio wavelpot</h3>","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"%%time\nfilename = \"../input/birdsong-recognition/train_audio/aldfly/XC134874.mp3\"\n\nwaveform, sample_rate = torchaudio.load(filename)\n\nplt.plot(waveform.t().numpy())","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<h3>Librosa wavelpot</h3>","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"%%time\nx,sr = librosa.load('../input/birdsong-recognition/train_audio/aldfly/XC134874.mp3')\nlibrosa.display.waveplot(x, sr=sr)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"librosa.feature.melspectrogram(x, sr=sample_rate, n_mels=128)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"<h3>Torchaudio Spectogram and MelSpectogram</h3>","execution_count":null},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"%%time\nfig, ax = plt.subplots(1, 2, figsize=(16, 12))\n\nax[0].imshow(torchaudio.transforms.Spectrogram(n_fft=2000)(waveform).log2()[0,:,:].numpy(), cmap='ocean');\nax[0].set_title('Spectrogram');\nax[1].imshow(torchaudio.transforms.MelSpectrogram(n_fft=16000)(waveform).log2()[0].numpy(), cmap='inferno');\nax[1].set_title('MelSpectrogram');","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"%%time\nX = librosa.stft(x)\nXdb = librosa.amplitude_to_db(abs(X))\nplt.figure(figsize=(14, 5))\nlibrosa.display.specshow(Xdb, sr=sr, x_axis='time', y_axis='hz')\nplt.colorbar()","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}