一个数组的索引太多

too many indicies for an array

我在 i want to get the same result. but in My case it plots the first image

中使用了用户 Anil_M 的代码

然后我得到一个错误

Traceback (most recent call last):
  File "c:/Users/Maram/Desktop/Spectrogram/first_attempt.py", line 73, in <module>
    fftArray = fftArray[0:numUniquePoints]
TypeError: slice indices must be integers or None or have an __index__ method 

我不明白

或者当我尝试使用稍大的 wav 文件时,它甚至不显示第一张图像。我刚收到这个错误:

Traceback (most recent call last):
      File "c:/Users/Maram/Desktop/Spectrogram/first_attempt.py", line 38, in <module>
        mySoundOneChannel = mySound[:,0]
    IndexError: too many indices for array

我认为这些错误在某种程度上是相关的,但我只是不明白它是如何或为什么导致的。

有人可以帮我把它变成 运行 更大的 wav file/longer 轨道,或者帮我把我现有的代码变成 运行 功率对频率图吗? 任何帮助将非常感激。

(我不知道这是否被认为是重复的——在最初的问题中,没有人遇到我面临的相同问题。)

语句mySoundOneChannel = mySound[:,0]读取文件的第一个通道。如果您的文件仅包含 1 个频道,请将其更改为 mySoundOneChannel = mySound[0:]

至于第二期 - numUniquePointsfloat 类型,所以你必须转换它 - numUniquePoints = int(numpy.ceil((mySoundLength + 1) / 2.0)).