Librosa 功能 tonnetz 以 TypeError 结束

Librosa feature tonnetz ends up in TypeError

我正在尝试从音频的谐波分量中提取音调。我的代码基本上是教程 https://librosa.github.io/librosa/generated/librosa.feature.tonnetz.html

的复制粘贴

我的代码:

import librosa

def extract_feature(file_name):
    y, sr = librosa.load(file_name)
    y = librosa.effects.harmonic(y)
    tonnetz = librosa.feature.tonnetz(y=y, sr=sr)
    return tonnetz


print extract_feature("out.wav")

这是堆栈跟踪:

/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/librosa/core/pitch.py:160: DeprecationWarning: object of type <type 'numpy.float64'> cannot be safely interpreted as an integer.
  bins = np.linspace(-0.5, 0.5, np.ceil(1./resolution), endpoint=False)
Traceback (most recent call last):
  File "test_python.py", line 10, in <module>
    print extract_feature("out.wav")
  File "test_python.py", line 6, in extract_feature
    tonnetz = librosa.feature.tonnetz(y=y, sr=sr)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/librosa/feature/spectral.py", line 1157, in tonnetz
    chroma = chroma_cqt(y=y, sr=sr)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/librosa/feature/spectral.py", line 936, in chroma_cqt
    real=False))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/librosa/core/constantq.py", line 251, in cqt
    cqt_resp.append(__cqt_response(my_y, n_fft, my_hop, fft_basis))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/librosa/core/constantq.py", line 531, in __cqt_response
    D = stft(y, n_fft=n_fft, hop_length=hop_length, window=np.ones)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/librosa/core/spectrum.py", line 167, in stft
    y_frames = util.frame(y, frame_length=n_fft, hop_length=hop_length)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/librosa/util/utils.py", line 102, in frame
    strides=(y.itemsize, hop_length * y.itemsize))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/stride_tricks.py", line 102, in as_strided
    array = np.asarray(DummyArray(interface, base=x))
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/numeric.py", line 531, in asarray
    return array(a, dtype, copy=False, order=order)
TypeError: 'float' object cannot be interpreted as an index

知道如何解决这个问题吗?

我回滚到 numpy 1.10.1 来解决这个问题(虽然我是 运行 chroma_cqt 并得到这个错误)。

Numpy > 1.11 as_strided 创建了一个虚拟数组,而 asarray 无法正确处理浮点数组。显然,1.10.1 numpy 有更好的 stride_tricks。