<jupyter_start><jupyter_text>Leopard seal vocalizationsSource:- https://www.mobysound.org/- http://localhost:8186/tree/Datasets/mobysound/leopard_seal**Note**: This dataset is very noisy<jupyter_code>from pathlib2 import Path
import numpy as np 
import pandas as pd
import matplotlib.pyplot as plt
import tensorflow as tf
from tqdm.autonotebook import tqdm
from librosa.core.time_frequency import mel_frequencies
from avgn_paper.signalprocessing.spectrogramming_tf import spectrogram_tensorflow
from avgn_paper.utils.audio import load_wav, float32_to_int16, int16_to_float32, write_wav
from avgn_paper.visualization.spectrogram import visualize_spec, plot_spec
from avgn_paper.utils.general import HParams
from avgn_paper.signalprocessing.filtering import butter_bandpass_filter<jupyter_output><empty_output><jupyter_text>data locations<jupyter_code>DSLOC = Path('/mnt/cube/Datasets/mobysound/leopard_seal/')
readme = DSLOC/'readme_1st.txt'
readme = [line for line in open(readme, 'r')]<jupyter_output><empty_output><jupyter_text>Load labels<jupyter_code>LABEL_LOC = DSLOC / 'low_double_trill.xls'
rate = 1000
def get_sec(time_str):
    if '.' in time_str:
        time_str, ms = time_str.split('.')
    else:
        ms = '0'
    h, m, s = time_str.split(':')
    return int(h) * 3600 + int(m) * 60 + int(s) + float('.'+ms)
label_df = pd.read_excel(LABEL_LOC)
label_df['start_time_s'] = [get_sec(time_str) for time_str in label_df['Start time [hh:mm:ss.ss]'].values]
label_df['end_time_s'] = [get_sec(time_str) for time_str in label_df['End time [hh:mm:ss.ss]'].values]
len(label_df)
label_df[:3]<jupyter_output><empty_output><jupyter_text>Make wav dataset<jupyter_code>wavs = list((DSLOC / 'data').glob('2*.wav'))
wavs.sort()
len(wavs)
wavs[:3]
long_wav = np.concatenate([load_wav(wav_loc)[1] for wav_loc in tqdm(wavs)])
len(long_wav)
wav_ds = pd.DataFrame(columns = ['rate', 'data', 'file', 'wloc', 'wav_st', 'wav_et', 'ds_len'])
st = 0
for wav_loc in tqdm(wavs):
    rate, data = load_wav(wav_loc)
    ds_len = len(data)/rate
    wav_ds.loc[len(wav_ds)] = [rate, data, wav_loc.stem, wav_loc, st, st+ds_len, ds_len]
    st+=ds_len
np.unique(wav_ds.rate.values)
wav_ds[:5]<jupyter_output><empty_output><jupyter_text>grab a single test syllable<jupyter_code>win_length_ms = 100
hop_length_ms = 10
print(win_length_ms/1000*rate)
hparams = HParams(  
    # spectrogramming
    win_length = int(rate/1000 * win_length_ms),
    n_fft = 2048,
    hop_length= int(rate/1000 * hop_length_ms),
    ref_level_db = 20,
    min_level_db = -70,
    # mel scaling
    num_mel_bins = 64,
    mel_lower_edge_hertz = 0,
    mel_upper_edge_hertz = 2000,
    # inversion
    power = 1.5, # for spectral inversion
    griffin_lim_iters = 50,
    pad=True,
    #
)
syll_row
syll_row = label_df.iloc[1000]
syll_data = long_wav[int(syll_row.start_time_s*rate):int(syll_row.end_time_s*rate)]
#syll_data = butter_bandpass_filter(syll_data, lowcut = syll_row['Low frequency [Hz]'], highcut=syll_row['High frequency [Hz]'], fs=rate, order=2)
spectrogram = spectrogram_tensorflow(int16_to_float32(syll_data), hparams)
fig, ax = plt.subplots(figsize=(10,5))
ax.matshow(spectrogram.numpy().T, origin='lower', aspect='auto', cmap = plt.cm.afmhot)
ax.axis('off')<jupyter_output><empty_output><jupyter_text>make syllable dataset<jupyter_code>syllable_df = pd.DataFrame(columns=["data", "start_time_s", "end_time_s"])
for idx, syll_row in tqdm(label_df.iterrows(), total=len(label_df)):
    syll_data = long_wav[
        int(syll_row.start_time_s * rate) : int(syll_row.end_time_s * rate)
    ]
    #syll_data = butter_bandpass_filter(
    #    syll_data,
    #    lowcut=syll_row["Low frequency [Hz]"],
    #    highcut=syll_row["High frequency [Hz]"],
    #    fs=rate,
    #    order=2,
    #)
    #spectrogram = spectrogram_tensorflow(int16_to_float32(syll_data), hparams)
    syllable_df.loc[len(syllable_df)] = [
        syll_data,
        syll_row.start_time_s,
        syll_row.end_time_s,
    ]<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup