python绘制音量图

import librosa
import librosa.display
import matplotlib.pyplot as plt
from matplotlib.patches import Rectangle

# 加载音频文件
audio_path = 'path/to/audio/file.wav'
audio, sr = librosa.load(audio_path)

# 提取音频振幅信息
amplitude = librosa.amplitude_to_db(librosa.stft(audio), ref=np.max)

# 绘制振幅图
plt.figure(figsize=(12, 4))
ax = plt.gca()
librosa.display.specshow(amplitude, sr=sr, x_axis='time', y_axis='log', ax=ax)
plt.colorbar(format='%+2.0f dB')
plt.title('振幅图')
plt.xlabel('时间 (秒)')
plt.ylabel('频率 (Hz)')
plt.tight_layout()

# 在指定的时间段上添加标记
time_ranges = [(2.0, 4.0), (5.0, 7.0), (8.0, 10.0)]  # 指定的时间段,单位为秒
freq_range = (10, sr/2)  # 定义频率范围
for start, end in time_ranges:
    rect = Rectangle((start, freq_range[0]), end - start, freq_range[1] - freq_range[0], 
                     linewidth=1, edgecolor='r', facecolor='
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值