<jupyter_start><jupyter_text>Automatically Removed the Audio between 2 Dog ClicksWe can use matplotlib and numpy to load a wav file and graph it to see what the dog clicker looks like.From https://stackoverflow.com/questions/18625085/how-to-plot-a-wav-file<jupyter_code>import matplotlib.pyplot as plt
import numpy as np
import wave
import sys

spf = wave.open("wavfile.wav", "r")
signal = spf.readframes(-1)
signal = np.fromstring(signal, "Int16")


plt.figure(1)
plt.xlim(0, 300000)
plt.title("Original Signal")
plt.ylim(-50000, 50000)
plt.plot(signal)
plt.show()<jupyter_output><empty_output><jupyter_text>Trimming the audio between clicksNow we can look for exceptionally loud signals, back-up a bit and cut to the next exceptionally loud signal. Currently this is done heuristically.<jupyter_code>shelf = 25000
preClickEcho = 500
clickEcho = 10000

trimmedSignal = []
i = 0
while i < len(signal):
    s = signal[i]
    if (-1 * shelf) < s > shelf:
            trimmedSignal = trimmedSignal[0:i - preClickEcho]
            i += clickEcho
            while i < len(signal) and (-1 * shelf) < signal[i] < shelf:
                i += 1
            i += clickEcho
    else:
        trimmedSignal.append(s)
        i += 1


plt.figure(1)
plt.xlim(0, 300000)
plt.title("Original Signal")
plt.ylim(-50000, 50000)
plt.plot(signal)


plt.figure(2)
plt.title("Without the section between clicks")
plt.plot(trimmedSignal)
plt.xlim(0, 300000)
plt.ylim(-50000, 50000)

plt.show()<jupyter_output><empty_output><jupyter_text>Exporting the modified wavNow we can write the file out using the parmaters from the original wav.<jupyter_code>print("exporting to trimmed.wav")
outputFile = wave.open("trimmed.wav", "wb")
outputFile.setnchannels(spf.getnchannels())
outputFile.setframerate(spf.getframerate())
outputFile.setsampwidth(spf.getsampwidth())

#print(type(trimmedSignal))
outputFile.writeframes(np.array(trimmedSignal).tobytes())
outputFile.close()
print("done")<jupyter_output>exporting to trimmed.wav
done
{'fraction_non_alphanumeric': 0.118, 'fraction_numerical': 0.0425, 'mean_word_length': 4.527624309392265, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 13, 'https://': 1, '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': '3', 'dir': 'jupyter-structured-clean-dedup', 'id': '256952', 'license': 'MIT', 'n_tokens_mistral': 779, 'n_tokens_neox': 689, 'n_words': 175, 'path': 'test.ipynb', 'repo_name': 'codingblocks/slycer', 'size': '2000'}