我遵循一些来自Librosa文件的示例代码,以显示STFT的光谱图。问题是,谱图从未出现过,当我在终端窗口中运行程序时,我简要地看到了程序的启动(与调用plt.show()时相同),但它立即消失了。
是否需要显式调用方法以在下面的代码中显示img对象?如果没有的话,是什么原因导致这个阴谋不出现呢?
# read the .wav file
audio, sample_rate = librosa.load("/Users/user/Desktop/voice.wav")
# perform stft using librosa module
audio_stft_1000 = np.abs(librosa.stft(audio, n_fft=1000))
audio_stft_3000 = np.abs(librosa.stft(audio, n_fft=3000))
# create plots according to docs linked above
fig, ax = plt.subplots()
img = librosa.display.specshow(librosa.amplitude_to_db(audio_stft_1000,
ref=np.max),
y_axis='log', x_axis='time', ax=ax)
ax.set_title('Power spectrogram')
fig.colorbar(img, ax=ax, format="%+2.0f dB")发布于 2022-10-05 01:04:56
非常简单的解决方案:
plt.show()https://stackoverflow.com/questions/73954663
复制相似问题