Python中最简单的方法是通过更长的顺序检测单个音频文件的时间放置?

发布于 2025-02-04 10:09:01 字数 391 浏览 3 评论 0原文

因此,确实让我对DAW Ableton Live感到困扰的事情是,它无法用节奏导出MIDI文件,这意味着不可能为一首歌而改变速度的歌曲创建可导出的节奏映射。但是,我可以轻松地对自己进行“节拍器”示例并将其作为音频文件进行排序。

因此,我想做的是在节拍器的简短样本中喂食这个长期渲染的节拍器波文件,找到每次点击的位置,然后自动生成一个带有bpm的MIDI轨道,并从该轨道上解释了SIG的变化。文件。

目前,我的愚蠢方法只是扫描第一个非零示例,创建事件,等待另一个零示例,然后重复直到文件完全读取。这可以正常工作,因为输入与单击相互切割,但是如果我可以检测到代表测量启动或第八笔记的不同声音,这样我也可以正确地检测到仪表会更好。

对最简单的进口方法的最简单方法有什么想法吗?只需要一个带有最小依赖性的轻量级脚本来制作克隆英雄图表。

So something that really bugs me about the DAW Ableton Live is that it cannot export MIDI files with tempo, meaning it's impossible to create an exportable tempo map for a song that changes speed throughout. But I am able to easily sequence a "metronome" sample myself and render that out as an audio file.

So what I'd like to do is to feed this long rendered metronome wave file in, alongside the short sample of the metronome, find the placement of every click, and then auto generate a midi track with bpm and time sig changes interpreted from the file.

Right now, my dumb approach is just to scan for the first non-zero sample, create the event, wait for another zero sample, and repeat until the file is fully read. This works ok because the input is silence inter-spliced with clicks, BUT it'd be nicer if I could detect different sounds that represent measure start or an eighth note division so I can also properly detect meter.

Any thoughts on the simplest way to do this with minimal imports? Just want a lightweight script with minimal dependencies to make clone hero charts.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

定格我的天空 2025-02-11 10:09:01

如Dankal444所述,可以使用称为相关性的信号处理技术来完成。计算两个信号的相关性将创建一个新信号,该信号具有两个信号匹配的峰值。这是使用Scipy和Numpy的示例。

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

This can be done with the signal processing technique called correlation, as dankal444 mentioned. Calculating the correlation of two signals will create a new signal that has peaks where the two signals match. Here is an example using scipy and numpy.

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文