beetbox / pyacoustid

Python bindings for Chromaprint acoustic fingerprinting and the Acoustid Web service
MIT License
325 stars 66 forks source link

python 3 chromaprint.feed #50

Closed victusfate closed 5 years ago

victusfate commented 5 years ago

I ran into a problem passing in a numpy.array memoryview to acoustid.fingerprint.

           # f_scaled is a np.int16 array
            buffer1 = f_scaled.data
            fp_encoded = acoustid.fingerprint(
                SAMPLE_RATE, channels, [buffer1], len(f_scaled))

I could definitely be doing something wrong (new to python signal processing) But I ended up getting it to process by modifying my local chromaprint.py near here https://github.com/beetbox/pyacoustid/blob/master/chromaprint.py#L122

           # data = str(data) 
          data = data.tobytes()
sampsyo commented 5 years ago

Hmm—the docstring says:

Data may be either a bytestring or a buffer object.

So I think this is probably behaving as expected? Can you just do the tobytes conversion in your code before passing the result into the library?

sampsyo commented 5 years ago

Oh wait, this is not a funky numpy thing but a proper memoryview! Sorry, I misunderstood.

Indeed, we should probably do that on Python 3 and continue to use str on Python 2.

victusfate commented 5 years ago

happy to try whatever you suggest 👍 it looks like the change is working for me locally, happy to assist with a PR

victusfate commented 5 years ago

feel free to take it or leave it (needs python 2 testing) 😄 https://github.com/beetbox/pyacoustid/pull/51