【问题标题】:Find timestamps of notes played in wav file [closed]查找在 wav 文件中播放的音符的时间戳 [关闭]
【发布时间】:2016-05-05 11:23:57
【问题描述】:

假设我们有一个 wav 文件,其中录制了一些吉他音乐。声音非常干净,没有多余的声音,只有吉他本身和节拍器的滴答声。

在 Python 中找到每个音符(或和弦)的时间戳的最佳方法是什么?我不需要识别笔记本身,只需要识别它发生时的时间戳。

我以前从未做过这种事情,所以我有点困惑。我在 Wikipedia 上阅读了有关短时傅立叶变换的信息,它看起来很有希望,但我找不到任何相关的例子。非常感谢任何有关如何开始的帮助/提示。

【问题讨论】:

标签: python audio onset-detection


【解决方案1】:

一般问题称为onset detection,您可以尝试多种方法。我将提供一个超级幼稚的解决方案,可能不适用于您的用例:

from scipy.io import wavfile
from scipy.signal import argrelmax
from matplotlib.mlab import specgram

sr, x = wavfile.read(path)                                    # read in a mono wav file
spec, freqs, time = specgram(x, NFFT=4096, Fs=sr, mode='psd') # compute power spectral density spectogram
spec2 = np.diff(spec, axis=1)                                 # discrete difference in each frequency bin
spec2[spec2<0] = 0                                            # half-wave rectification
diff = np.sum(spec2, axis=0)                                  # sum positive difference in each time bin

for peak in argrelmax(diff)[0]:                               # find peaks
    print("onset between %f and %f." % (time[peak], time[peak+1]))

【讨论】:

  • 谢谢!这对我来说是一个很好的起点。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-09-25
  • 1970-01-01
  • 2013-12-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多