import librosa.display
import matplotlib.pyplot as plt
import numpy as np
audio_path = 't.wav'
y, sr = librosa.load(audio_path)
D = librosa.stft(y)
S_db = librosa.amplitude_to_db(np.abs(D), ref=np.max)
t = np.arange(S_db.shape[1])
f = np.arange(S_db.shape[0])
T, F = np.meshgrid(t, f)
Z = S_db
fig = plt.figure(figsize=(14, 8))
ax = fig.add_subplot(111, projection='3d')
ax.plot_surface(T, F, Z, cmap='viridis')
ax.set_xlabel('Time')
ax.set_ylabel('Frequency')
ax.set_zlabel('Magnitude (dB)')
ax.set_title('3D Spectrogram')
plt.show()
音频转3d图
于 2024-06-17 12:17:37 首次发布