<jupyter_start><jupyter_text><jupyter_code>%matplotlib inline
import pandas as pd
import os
import librosa
import librosa.display
import matplotlib.pyplot as plt
import numpy as np

def create_spectrogram(filename,no):
    plt.interactive(False)
    path = "Drive/Drive 2/Colab Notebooks/audio/"+filename
    clip, sample_rate = librosa.load(path, sr=None)
    fig = plt.figure(figsize=[1,1])
    ax = fig.add_subplot(111)
    ax.axes.get_xaxis().set_visible(False)
    ax.axes.get_yaxis().set_visible(False)
    ax.set_frame_on(False)
    S = librosa.feature.melspectrogram(y=clip, sr=sample_rate)
    librosa.display.specshow(librosa.power_to_db(S, ref=np.max))
    check_point = links["category"][no]
    if check_point!="coughing":
      filename = '/Drive/Drive 2/Colab Notebooks/Data/Non-Cough/' + filename + '.png'
    else:
      filename = '/Drive/Drive 2/Colab Notebooks/Data/Cough/' + filename + '.png'
    plt.savefig(filename, dpi=400, bbox_inches='tight',pad_inches=0)
    plt.close()    
    fig.clf()
    plt.close(fig)
    plt.close('all')
links = pd.read_csv("/Drive/Drive 2/Colab Notebooks/meta/esc50.csv")
links.columns
links.head(10)
len_N = len(links)
for i in range(len_N):
  filename = links["filename"][i]
  create_spectrogram(filename, i)
  print(i)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14022988505747128, 'fraction_numerical': 0.013026819923371647, 'mean_word_length': 4.308943089430894, 'pattern_counts': {'":': 1, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '502913', 'license': 'MIT', 'n_tokens_mistral': 519, 'n_tokens_neox': 492, 'n_words': 84, 'path': '01. Spectrogram.ipynb', 'repo_name': 'kartikay-99k/Cough-detector-app', 'size': '1305'}