首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Python中,检测单个音频文件在较长序列上的时间位置的最简单方法是什么?

在Python中,检测单个音频文件在较长序列上的时间位置的最简单方法是什么?
EN

Stack Overflow用户
提问于 2022-06-05 16:59:33
回答 1查看 229关注 0票数 0

所以,DAW Ableton Live真正困扰我的一点是,它不能导出带有tempo的MIDI文件,这意味着不可能为一首歌曲创建一个可导出的节奏地图,它可以在整个过程中改变速度。但我可以很容易地排序一个“节拍器”样本,并把它作为一个音频文件。

所以我想要做的是把这个长时间呈现的节拍器波形文件和节拍器的简短示例放在一起,找到每一次点击的位置,然后自动生成一个midi轨道,其中包含bpm和从文件中解释的时间sig更改。

现在,我的愚蠢方法只是扫描第一个非零样本,创建事件,等待另一个零样本,然后重复直到文件被完全读取。这是好的,因为输入是与点击之间的静默,但如果我能检测到不同的声音,代表测量开始或第八个音符分割,我也能正确地检测到仪表,这会更好。

有没有想过用最少的进口来做这件事的最简单的方法?只是想要一个轻量级的脚本与最小的依赖关系,使克隆英雄图表。

EN

回答 1

Stack Overflow用户

发布于 2022-06-08 20:10:18

正如dankal444所提到的,这可以通过称为相关的信号处理技术来完成。计算两个信号的相关性将产生一个新的信号,该信号具有两个信号匹配的峰值。下面是一个使用scipy和numpy的例子。

代码语言:javascript
复制
from scipy import signal
import numpy as np

# TODO: - load sound signal and metronome sample as numpy arrays
#       - specify sample_rate
#       - tune detection_threshold

def find_clicks (sound, metronome_sample, sample_rate, detection_threshold):
    # Correlate the sound with the metronome sample
    corr_full = signal.correlate(sound, metronome_sample)
    # Remove backward correlated sound
    corr = corr_full[len(corr_full)//2:]

    # Find the peaks using the find_peaks algorithm
    # Specify a minimum height that the peaks must be above with "detection_threshold"
    peaks, properties = signal.find_peaks(corr, height=detection_threshold)
    # "peaks" will contain the placement of every click in sample count

    # Calculate the mean distance between each peak to find the period
    period = np.mean([peaks[i + 1] - peaks[i] for i in range(len(peaks) -1)])

    # BPM [beat/m]: sample rate [S/s] * 60 / ( period [S/beat])
    bpm =  sample_rate * 60/period

    return peaks, bpm
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/72509397

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档