【问题标题】:Save spectrogram as image without displaing it. Google colab将频谱图保存为图像而不显示它。谷歌合作实验室
【发布时间】:2021-03-14 02:25:59
【问题描述】:

我有大约 5000 个音频样本,并制作了每个样本的频谱图并保存为图像。我已经知道如何用 librosa 制作频谱图,显示它并保存在正确的图像中。但是每次在保存图像之前都会感到沮丧。用所有 5000 个样本做这个不是一个好主意。是否可以在不显示的情况下保存图像?

import numpy as np
import librosa
import librosa.display
import matplotlib.pyplot as plt

f_name = # path to current file
path = # path where to save result

X, s_rate = librosa.load(f_name, res_type='kaiser_fast', duration=4.0)

mfc = librosa.feature.melspectrogram(y=X, sr=s_rate)
ch = librosa.feature.chroma_stft(y=X, sr=s_rate)
sc = librosa.feature.spectral_contrast(y=X, sr=s_rate)
tz = librosa.feature.tonnetz(y=X, sr=s_rate)

small_MFCC = np.concatenate([mfc, ch, sc, tz], axis=0)
librosa.display.specshow(small_MFCC)
plt.savefig(path, bbox_inches="tight", pad_inches=0.0)

【问题讨论】:

  • 我发现,当我将它放入 for 循环时,只会显示最后一个频谱图。所以它以某种方式自行工作

标签: python matplotlib conv-neural-network librosa image-classification


【解决方案1】:

最好不要使用绘图来将频谱图/倒谱保存为图像。为此,请参阅此帖子:How can I save a Librosa spectrogram plot as a specific sized image?

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-08-02
    • 2021-06-13
    • 1970-01-01
    • 2021-11-27
    • 1970-01-01
    • 1970-01-01
    • 2018-04-23
    • 1970-01-01
    相关资源
    最近更新 更多