(audio, threshold)
return audio_trim, left_blank, right_blank
Removes silence at the beginning and end of a sample.
Removes silence at the beginning and end of a sample.
Removes silence at the beginning and end of a sample .
def trim_silence(audio, threshold):
        """Removes silence at the beginning and end of a sample."""
        energy = librosa.feature.rms(audio)
        frames = np.nonzero(np.array(energy > threshold))
        indices = librosa.core.frames_to_samples(frames)[1]

        # Note: indices can be an empty array, if the whole audio was silence.
        audio_trim = audio[0:0]
        left_blank = audio[0:0]
        right_blank = audio[0:0]
        if indices.size:
            audio_trim = audio[indices[0]:indices[-1]]
            left_blank = audio[:indices[0]]  # slice before.
            right_blank = audio[indices[-1]:]  # slice after.
        return audio_trim, left_blank, right_blank
def trim_silence ( audio , threshold ) : energy = librosa . feature . rms ( audio ) frames = np . nonzero ( np . array ( energy > threshold ) ) indices = librosa . core . frames_to_samples ( frames ) [ 1 ] # Note: indices can be an empty array, if the whole audio was silence. audio_trim = audio [ 0 : 0 ] left_blank = audio [ 0 : 0 ] right_blank = audio [ 0 : 0 ] if indices . size : audio_trim = audio [ indices [ 0 ] : indices [ - 1 ] ] left_blank = audio [ : indices [ 0 ] ] # slice before. right_blank = audio [ indices [ - 1 ] : ] # slice after. return audio_trim , left_blank , right_blank