def trim_silence(audio, threshold):
 energy = librosa.feature.rmse(audio)
 frames = np.nonzero((energy > threshold))
 indices = librosa.core.frames_to_samples(frames)[1]
 return (audio[indices[0]:indices[(-1)]] if indices.size else audio[0:0])

def trim_silence ( audio , threshold ) : energy = librosa . feature . rmse ( audio ) frames = np . nonzero ( ( energy > threshold ) ) indices = librosa . core . frames_to_samples ( frames ) [ 1 ] return ( audio [ indices [ 0 ] : indices [ ( - 1 ) ] ] if indices . size else audio [ 0 : 0 ] )
removes silence at the beginning and end of a sample .