The use of librosa.effects.trim to remove the silent part in audio

2k Views Asked by At

I am doing a speech emotion recognition ML.

I currently use pyAudioAnalysis to do a multi-directory feature extraction. However, the dataset involved in audios containing a lot of approximately silent sections. My objective is to remove the approximately silent parts from all the audios then extract meaningful features.

My current approach is to use librosa to trim the silent parts.

from librosa.effects import trim
import librosa
from pyAudioAnalysis import audioBasicIO
import matplotlib.pyplot as plt

signal, Fs = librosa.load(file_directory)
trimed_signal = trim(signal,top_db=60)


fig, ax = plt.subplots(nrows=3, sharex=True, sharey=True)
librosa.display.waveplot(trimed_signal, sr=Fs, ax=ax[0])
ax[0].set(title='Monophonic')
ax[0].label_outer()

I tried to plot the wave after trimming using librosa.display.waveplot but an AttributeError occurred showing AttributeError: module 'librosa' has no attribute 'display'

My questions are

  1. How to plot the trimmed wave?
  2. Is it possible to generate a trimmed .wav file? This is because pyAudioAnalysis's input for feature extraction is .wav file path but the output of librosa is array.
1

There are 1 best solutions below

4
On BEST ANSWER
  1. You need to import librosa.display separately. See this issue for the reason.
  2. You can use librosa.output.write_wav (check the docs) to store the trimmed array as a wave file. E.g. librosa.output.write_wav(path, trimed_signal, Fs).