itspoma / audio-fingerprint-identifying-python

The Shazam-similar app, that identify the song using audio fingerprints & spectrum analysis and Fast Fourier transform
MIT License
356 stars 166 forks source link

_UFuncNoLoopError: ufunc 'subtract' did not contain a loop with signature matching types (dtype('S8'), dtype('int64')) -> None #33

Open MeaningOfLights opened 3 months ago

MeaningOfLights commented 3 months ago

I'm running using Python 3.9 and I get this error:

numpy.core._exceptions._UFuncNoLoopError: ufunc 'subtract' did not contain a loop with signature matching types (dtype('S8'), dtype('int64')) -> None

With this line of code:

yield sid, offset - mapper[audio_hash]

To get around it I added a Try/Catch however I'm losing a lot of information and want to know the correct way to handle this?

        for hash, sid, offset in x:
            try:
                if isinstance(mapper[hash], bytes):
                    db_offset = int(mapper[hash].decode('utf-8'))
                elif isinstance(mapper[hash], (int, np.integer)):
                    db_offset = int(mapper[hash])
                else:
                    raise ValueError(f"Unsupported type for mapper[{hash}]: {type(mapper[hash])}")

                if isinstance(offset, bytes):
                    offset = int(offset.decode('utf-8'))
                elif not isinstance(offset, (int, np.integer)):
                    raise ValueError(f"Unsupported type for offset: {type(offset)}")

                yield (sid, offset - db_offset)
            except ValueError:
                print(f"Invalid value for mapper[{hash}]: {mapper[hash]} - Offset {offset}")    # Heaps are invalid
                continue
            except KeyError:
                print(f"Key {hash} not found in mapper")
                continue