<jupyter_start><jupyter_text>Padding and Augmentation<jupyter_code>fname = './test/short.wav'
short, _ = librosa.core.load(fname, sr=SR)
print('short length', len(short))
plt.figure(figsize=(16, 4))
plt.plot(short, '-', )
fname = './test/sil.wav'
sil, _ = librosa.core.load(fname, sr=SR)
print('long length', len(sil))
plt.figure(figsize=(16, 4))
plt.plot(sil, '-', )
#Concern is padding with zeros will result in the model just learning the length of the underlying samples
#or some other arbitrary feature. Using real background noise/silence from the recording env is likely better.
#Unsure if 1d conv net or spectrogram, mfcc models may be more sensitive to these problems than others.
zero_padded = random_pad(short, len(sil))
plt.figure(figsize=(16, 4))
plt.plot(zero_padded, '-', )
#random_pad_with uses underlying padding values, there are probably similar numpy functions
a = np.arange(10)
b = np.array([100,101,102,103])
c = random_pad_with(b,a)
c
sil_padded = random_pad_with(short, sil)
plt.plot(sil_padded, '-', )
#this assumes all files in silence dir are the max length
def random_silence_wav():
    for _, _, filenames in os.walk('./data/silence'):
        filename = filenames[np.random.randint(len(filenames))]
        wav, _ = librosa.core.load('./data/silence/' + filename, sr=16000)
        return wav

silence_wave = random_silence_wav()
len(silence_wave)
really_short = np.array([.01] * 3000)
padded = random_silence_pad(really_short)
plt.plot(padded, '-', )
#this grabs a random silence file from ./data/silence as the padding data
#if used, make sure all silence wavs are the max length!<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13032886723507917, 'fraction_numerical': 0.021315468940316686, 'mean_word_length': 5.107806691449814, 'pattern_counts': {'":': 0, '<': 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': '394914', 'license': 'MIT', 'n_tokens_mistral': 603, 'n_tokens_neox': 561, 'n_words': 161, 'path': 'audio_vis.ipynb', 'repo_name': 'grwgreg/streaming-audio-recognition', 'size': '1642'}