title: how can i crop out the part of audio with high amplitude faster
body: <p>what i need to do is to record a short audio of 2 seconds. my approach is to record 3 seconds and crop two seconds from it. </p>
  
  <p>for now i managed to achieve this by using a while loop and calculate the average of every 2sec ranges possible. as the rate is 40100 and the original length is 3 of that, this takes a long time to finish. </p>
  
  <pre><code>i = 0
  while i &lt; len(channel_1) - (2 * rate):
      avgs.append(get_average(channel_1[i:i + (2 * rate)]))
      i += 10   
  max_int = np.argmax(avgs) * 10
  new_audio = audio[max_int:max_int + (2 * rate)]
  </code></pre>
  
  <p>is there anyway how i can do this faster and more effectively than this.</p>
  
  <p><a href="https://i.stack.imgur.com/MLvfF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MLvfF.png" alt="enter image description here"></a></p>