AllenDowney / ThinkDSP

Think DSP: Digital Signal Processing in Python, by Allen B. Downey.
https://allendowney.github.io/ThinkDSP/
3.93k stars 3.2k forks source link

TypeError at use of make_spectrogram #66

Closed filipthor closed 3 years ago

filipthor commented 4 years ago

As the title reads, I have hit a bit of a snub trying the code out.

Trying to run the code: import thinkdsp

wave = thinkdsp.read_wave('100475iluppaisaxophone-weep.wav') spectrogram = wave.make_spectrogram(seg_length=512) spectrogram.plot(high=700)

on Python 3.6, resulting in: Traceback (most recent call last): ... File "/Users/filipthor/PycharmProjects/music/main.py", line 9, in spectrogram = wave.make_spectrogram(seg_length=512) File "/Users/filipthor/anaconda/lib/python3.6/site-packages/thinkdsp.py", line 943, in make_spectrogram segment = self.slice(i, j) File "/Users/filipthor/anaconda/lib/python3.6/site-packages/thinkdsp.py", line 897, in slice ys = self.ys[i:j].copy() TypeError: slice indices must be integers or None or have an index method

Any ideas?

filipthor commented 4 years ago

"ugly-fixed" it by wrapping i and j with int(), which seems to work

AllenDowney commented 4 years ago

In the current version,

        step = int(seg_length // 2)

so i and j should already be ints.

Maybe you have an older version of thinkdsp.py?

AllenDowney commented 3 years ago

I just ran a test with current version and all is well.