I have a sound signal, imported as a numpy array and I want to cut it into chunks of numpy arrays. However, I want the chunks to contain only elements above a threshold. For example:
threshold = 3
signal = [1,2,6,7,8,1,1,2,5,6,7]
should output two arrays
vec1 = [6,7,8]
vec2 = [5,6,7]
Ok, the above are lists, but you get my point.
Here is what I tried so far, but this just kills my RAM
def slice_raw_audio(audio_signal, threshold=5000):
signal_slice, chunks = [], []
for idx in range(0, audio_signal.shape[0], 1000):
while audio_signal[idx] > threshold:
signal_slice.append(audio_signal[idx])
chunks.append(signal_slice)
return chunks