【问题标题】:The use of librosa.effects.trim to remove the silent part in audio使用 librosa.effects.trim 去除音频中的静音部分
【发布时间】:2020-10-15 03:00:52
【问题描述】:

我正在做一个语音情感识别 ML。

我目前使用pyAudioAnalysis 进行多目录特征提取。然而,音频中涉及的数据集包含很多近似无声的部分。我的目标是从所有音频中删除几乎无声的部分,然后提取有意义的特征。

我目前的做法是使用librosa 来修剪静音部分。

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()

我尝试在使用librosa.display.waveplot 进行修剪后绘制波形,但出现显示 AttributeError: module 'librosa' has no attribute 'display' 的 AttributeError

我的问题是

  1. 如何绘制修剪后的波?
  2. 是否可以生成修剪后的 .wav 文件?这是因为pyAudioAnalysis的特征提取输入是.wav文件路径,而librosa的输出是数组。

【问题讨论】:

    标签: machine-learning audio deep-learning librosa


    【解决方案1】:
    1. 您需要单独import librosa.display。原因见this issue
    2. 您可以使用librosa.output.write_wav(检查the docs)将修剪后的数组存储为波形文件。例如。 librosa.output.write_wav(path, trimed_signal, Fs)

    【讨论】:

    • 遗憾的是 librosa 删除了输出功能。我尝试使用 pysoundfile 但它弹出错误 ValueError: dtype must be one of ['float32', 'float64', 'int16', 'int32']
    • 我设法安装了包含输出功能的早期版本的 librosa,但它给了我类似的错误:ParameterError: Audio data must be of type numpy.ndarray
    • 你传递的数据有什么dtype?
    • 由于 librosa 0.8.0 删除了输出功能,应该使用 soundfile 代替 pysoundfile.readthedocs.io/en/latest/index.html#soundfile.write
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-03-29
    • 2021-05-22
    • 2014-10-31
    • 2015-05-26
    • 2019-10-23
    • 2016-07-04
    • 1970-01-01
    相关资源
    最近更新 更多