上传音频文件生成频谱图
时间: 2024-01-09 11:04:49 浏览: 212
你可以使用Python中的音频处理库来生成音频文件的频谱图。下面是一个示例代码,使用Librosa库将音频文件转换为频谱图:
```python
import librosa
import librosa.display
import matplotlib.pyplot as plt
# 加载音频文件
audio_file = 'path/to/audio.wav'
audio, sr = librosa.load(audio_file)
# 生成频谱图
spectrogram = librosa.feature.melspectrogram(y=audio, sr=sr)
spectrogram_db = librosa.power_to_db(spectrogram, ref=np.max)
# 显示频谱图
plt.figure(figsize=(10, 4))
librosa.display.specshow(spectrogram_db, sr=sr, x_axis='time', y_axis='mel')
plt.colorbar(format='%+2.0f dB')
plt.title('Spectrogram')
plt.tight_layout()
plt.show()
```
请确保已经安装了Librosa和Matplotlib库,并将`'path/to/audio.wav'`替换为你的音频文件路径。运行代码后,将显示生成的频谱图。
阅读全文
相关推荐

















