shazamio / shazamio-core

MIT License
7 stars 3 forks source link

Use rubato & symphonia for decoding & resampling #10

Open Inrixia opened 6 months ago

Inrixia commented 6 months ago

Remove dependencies for:

Do all decode and resampling operations in memory using rubato & symphonia This removes the dependency on ffmpeg and no longer writes to disk

Code is ported from my web assembly fork of this https://github.com/Inrixia/shazamio-core/tree/wasm I figured I might aswell do a pr to integrate some of the improvements I did into the main python version. Its working perfectly fine there but I haven't tested it in the python version as I don't have the dev environment setup for it.

Inrixia commented 6 months ago

My WebAssembly branch has a bunch of fixes & improvements that may be worth reviewing before considering merging this

dotX12 commented 6 months ago

Hello, I couldn’t get it to work the first time, I see problems. Could you help with this?

mp3 file

2024-04-22 11:14:15 - asyncio - [proactor_events.py:633 - __init__()] - DEBUG - Using proactor: IocpProactor
thread 'tokio-runtime-worker' panicked at src\fingerprinting\decode.rs:61:48:
attempt to multiply with overflow
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'tokio-runtime-worker' panicked at src\utils.rs:21:14:
called `Result::unwrap()` on an `Err` value: JoinError::Panic(Id(35), ...)
Traceback (most recent call last):
  File "C:\Users\ecelo\PycharmProjects\ShazamIO\examples\recognize_song.py", line 46, in <module>
    loop.run_until_complete(main())
  File "C:\Users\ecelo\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\ecelo\PycharmProjects\ShazamIO\examples\recognize_song.py", line 34, in main
    new_version_path = await shazam.recognize("data/Joey_Bada_THE_REV3NGE.mp3")
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ecelo\PycharmProjects\ShazamIO\shazamio\api.py", line 559, in recognize
    signature = await self.core_recognizer.recognize_path(data)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pyo3_asyncio.RustPanic: rust future panicked: unknown error

Process finished with exit code 1

ogg file

2024-04-22 11:15:45 - asyncio - [proactor_events.py:633 - __init__()] - DEBUG - Using proactor: IocpProactor
Traceback (most recent call last):
  File "C:\Users\ecelo\PycharmProjects\ShazamIO\examples\recognize_song.py", line 46, in <module>
    loop.run_until_complete(main())
  File "C:\Users\ecelo\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\Users\ecelo\PycharmProjects\ShazamIO\examples\recognize_song.py", line 34, in main
    new_version_path = await shazam.recognize("data/dora.ogg")
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ecelo\PycharmProjects\ShazamIO\shazamio\api.py", line 559, in recognize
    signature = await self.core_recognizer.recognize_path(data)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
SignatureError: unsupported feature: core (codec):unsupported codec
Inrixia commented 6 months ago

Hey, sorry yea I didn't have a python env so just did a dirty port of my branch (which has progressed a lot since then) If you have a look at the state of the codebase on my wasm fork you can see the changes I have made. https://github.com/Inrixia/shazamio-core

Currently alongside completely removing the ffmpeg dependency it also only calculates data as needed and has additional options allowing for grabbing a specific area of a file.

I don't have the time to setup a python environment for porting my changes but it should be very easy for you to grab a fork of my branch and just add some new python types around the code to test it, are you able to do that?