确实存在基于音频波形振幅变化来捕捉卡点位置的方法,这种方法特别适合强调重音、爆炸音效等明显音量变化的场景。以下是结合波形能量分析的完整解决方案:
---
### 一、核心原理
通过分析音频信号的 **RMS能量(均方根能量)** 或 **峰值振幅**,检测能量突变点(能量显著上升沿)作为视觉卡点位置。
```python
音频信号 → 分帧处理 → 计算能量 → 阈值检测 → 时间点定位
```
---
### 二、完整代码实现
```python
import librosa
import numpy as np
import matplotlib.pyplot as plt
from moviepy.editor import *
def waveform_based_cut_points(audio_path, threshold=0.2, pre_max=10, post_max=10):
"""基于波形能量的卡点检测"""
y, sr = librosa.load(audio_path, sr=None)
# 计算能量包络
rms = librosa.feature.rms(y=y)[0]
times = librosa.times_like(rms, sr=sr)
# 寻找能量突变点
peaks = np.where(rms > threshold * np.max(rms))[0]
# 合并邻近峰值
peaks_clean = []
prev = -100
for p in peaks:
if p - prev > post_max:
peaks_clean.append(p)
prev = p
return times[peaks_clean]
def visualize_detection(audio_path, cut_times):
"""可视化检测结果"""
plt.figure(figsize=(15,5))
y, sr = librosa.load(audio_path)
librosa.display.waveshow(y, sr=sr, alpha=0.5)
plt.vlines(cut_times, -1, 1, color='r', linestyle='--')
plt.title('Waveform-Based Cut Points Detection')
plt.show()
# 使用示例
audio_path = "music.mp3"
cut_times = waveform_based_cut_points(audio_path)