GithubHelp home page GithubHelp logo

bayernmuller / vibra Goto Github PK

View Code? Open in Web Editor NEW
21.0 1.0 2.0 698 KB

🎵 A cross-platform C++ Shazam client that identifies music files and fetches song details from Shazam.

License: GNU General Public License v3.0

C++ 94.96% CMake 1.26% C 1.51% HTML 1.95% Dockerfile 0.33%
cpp music-fingerprinting music-recognition shazam crossplatform fingerprint opensource webassembly

vibra's Introduction


vibra

What is vibra?

  • vibra is a C++ music file recognition tool that uses an unofficial Shazam API.
  • vibra analyzes music files and returns fingerprint data. It searches the Shazam database to identify the song.
  • The Shazam algorithm is based on:
  • I referenced the Rust implementation of the Shazam client code from SongRec.
  • I created this project for embedded devices such as Raspberry Pi or Jetson Nano, which are challenging to set up with Python or Rust environments.

Compatibility table

Platform Architecture Build Status
WebAssembly -
Linux x86_64
Linux ARM64
Windows x86_64
macOS x86_64
macOS ARM64
Raspberry Pi 4 ARMv8-A
Raspberry Pi Zero ARMv6

Build vibra

Requirements

  • vibra uses CMake for building. You need to install CMake to build vibra.
  • vibra utilizes C++11 features.
  • vibra depends on the following libraries or tools:
    • CMake: To build the project.
    • libcurl: To send HTTP requests to the Shazam API.
    • libfftw3: To calculate the Fast Fourier Transform.
    • (Optional) FFmpeg: To decode audio files other than WAV. (e.g., MP3, FLAC, etc.)
      • If you want to want recognize non-WAV files, you need to install FFmpeg on your system.

Install dependencies

  • Ubuntu
    • sudo apt-get install cmake libcurl4-openssl-dev libfftw3-dev
    • sudo apt-get install ffmpeg (Optional)

Build

  • Clone repository recursively to include submodules.

    • git clone --recursive https://github.com/bayernmuller/vibra.git
  • Run the following commands to build vibra:

    • mkdir build && cd build
    • cmake ..
    • make

Usage

Use --help option to see the help message.
vibra {COMMAND} [OPTIONS]

Options:

  Commands:
      -F, --fingerprint                     Generate a fingerprint
      -R, --recognize                       Recognize a song
      -h, --help                            Display this help menu
  Sources:
      File sources:
          -f, --file                            File path
      Raw PCM sources:
          -s, --seconds                         Chunk seconds
          -r, --rate                            Sample rate
          -c, --channels                        Channels
          -b, --bits                            Bits per sample
- recognizing song from wav file
vibra --recognize --file sample.wav > result.json

jq .track.title result.json
"Stairway To Heaven"
jq .track.subtitle result.json
"Led Zeppelin"
jq .track.share.href result.json
"https://www.shazam.com/track/5933917/stairway-to-heaven"
- recognizing song from microphone
  • You can use sox or FFmpeg to print raw PCM data from microphone.
sox -d -t raw -b 24 -e signed-integer -r 44100 -c 1 - 2>/dev/null
| vibra --recognize --seconds 5 --rate 44100 --channels 1 --bits 24 > result.json

jq .track.title result.json
"Bound 2"
jq .track.subtitle result.json
"Kanye West"
jq .track.sections[1].text result.json
[
  "B-B-B-Bound to fall in love",
  "Bound to fall in love",
  "(Uh-huh, honey)",
  ...
]
- recognizing non-WAV files
  • You need to install FFmpeg on your system to decode non-WAV media files.
  • Vibra will try to locate FFmpeg in your PATH environment variable. Alternatively, you can specify the FFmpeg path by setting the FFMPEG_PATH environment variable.
# Automatically find FFmpeg in PATH
vibra --recognize --file out.mp3

# Specify the FFmpeg path
export FFMPEG_PATH=/opt/homebrew/bin/ffmpeg
vibra --recognize --file out.mp3
  • You can see the sample shazam result json file in here

Performance comparison


lower is better

  • I compared the performance of vibra with the SongRec rust and python version on the Raspberry Pi 4.
  • vibra is about 2 times faster than the SongRec!

WebAssembly Version Support

Demo Video

  • Real time music tracker and lighting solution "Mooding", which uses vibra.
  • Click to view!

Mooding

License

  • vibra is licensed under the GPLv3 license. See LICENSE for more details.

vibra's People

Contributors

bayernmuller avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

vibra's Issues

Segmentation Fault on WAV Recognition Using vibra Command

./vibra --recognize --wav in.wav > result.json
[1] 10463 segmentation fault (core dumped) ./vibra --recognize --wav in.wav > result.json

there are also compilation warnings:
mkdir build && cd build cmake .. make -- The C compiler identification is GNU 13.2.0 -- The CXX compiler identification is GNU 13.2.0 -- Detecting C compiler ABI info -- Detecting C compiler ABI info - done -- Check for working C compiler: /usr/bin/cc - skipped -- Detecting C compile features -- Detecting C compile features - done -- Detecting CXX compiler ABI info -- Detecting CXX compiler ABI info - done -- Check for working CXX compiler: /usr/bin/c++ - skipped -- Detecting CXX compile features -- Detecting CXX compile features - done -- Configuring done (0.7s) -- Generating done (0.0s) -- Build files have been written to: /home/sever-in/vibra/build [ 12%] Building CXX object CMakeFiles/vibra.dir/cli/main.cpp.o [ 25%] Building CXX object CMakeFiles/vibra.dir/cli/cli.cpp.o /home/sever-in/vibra/cli/cli.cpp: In constructor ‘CLI::CLI(int, char**)’: /home/sever-in/vibra/cli/cli.cpp:43:18: warning: catching polymorphic type ‘class args::Help’ by value [-Wcatch-value=] 43 | catch (args::Help) | ^~~~ /home/sever-in/vibra/cli/cli.cpp:48:29: warning: catching polymorphic type ‘class args::ParseError’ by value [-Wcatch-value=] 48 | catch (args::ParseError e) | ^ /home/sever-in/vibra/cli/cli.cpp:56:34: warning: catching polymorphic type ‘class args::ValidationError’ by value [-Wcatch-value=] 56 | catch (args::ValidationError e) | ^ [ 37%] Building CXX object CMakeFiles/vibra.dir/fingerprinting/algorithm/signature.cpp.o [ 50%] Building CXX object CMakeFiles/vibra.dir/fingerprinting/algorithm/frequency.cpp.o [ 62%] Building CXX object CMakeFiles/vibra.dir/fingerprinting/algorithm/signature_generator.cpp.o [ 75%] Building CXX object CMakeFiles/vibra.dir/fingerprinting/audio/wav.cpp.o In file included from /usr/include/c++/13/bits/shared_ptr.h:53, from /usr/include/c++/13/memory:80, from /home/sever-in/vibra/fingerprinting/audio/wav.h:6, from /home/sever-in/vibra/fingerprinting/audio/wav.cpp:1: In constructor ‘std::__shared_count<_Lp>::__shared_count(_Ptr) [with _Ptr = unsigned char*; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’, inlined from ‘std::__shared_count<_Lp>::__shared_count(_Ptr, std::false_type) [with _Ptr = unsigned char*; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’ at /usr/include/c++/13/bits/shared_ptr_base.h:928:22, inlined from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(_Yp*) [with _Yp = unsigned char; <template-parameter-2-2> = void; _Tp = unsigned char; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’ at /usr/include/c++/13/bits/shared_ptr_base.h:1469:17, inlined from ‘std::shared_ptr<_Tp>::shared_ptr(_Yp*) [with _Yp = unsigned char; <template-parameter-2-2> = void; _Tp = unsigned char]’ at /usr/include/c++/13/bits/shared_ptr.h:214:46, inlined from ‘Wav::Wav(const char*, uint32_t, uint32_t, uint32_t, uint32_t)’ at /home/sever-in/vibra/fingerprinting/audio/wav.cpp:32:18: /usr/include/c++/13/bits/shared_ptr_base.h:921:15: warning: ‘void operator delete(void*)’ called on pointer returned from a mismatched allocation function [-Wmismatched-new-delete] 921 | delete __p; | ^~~~~~~~~~ /home/sever-in/vibra/fingerprinting/audio/wav.cpp: In constructor ‘Wav::Wav(const char*, uint32_t, uint32_t, uint32_t, uint32_t)’: /home/sever-in/vibra/fingerprinting/audio/wav.cpp:32:72: note: returned from ‘void* operator new [](std::size_t)’ 32 | mData = std::shared_ptr<std::uint8_t>(new std::uint8_t[raw_pcm_size]); | ^ In constructor ‘std::__shared_count<_Lp>::__shared_count(_Ptr) [with _Ptr = unsigned char*; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’, inlined from ‘std::__shared_count<_Lp>::__shared_count(_Ptr, std::false_type) [with _Ptr = unsigned char*; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’ at /usr/include/c++/13/bits/shared_ptr_base.h:928:22, inlined from ‘std::__shared_ptr<_Tp, _Lp>::__shared_ptr(_Yp*) [with _Yp = unsigned char; <template-parameter-2-2> = void; _Tp = unsigned char; __gnu_cxx::_Lock_policy _Lp = __gnu_cxx::_S_atomic]’ at /usr/include/c++/13/bits/shared_ptr_base.h:1469:17, inlined from ‘std::shared_ptr<_Tp>::shared_ptr(_Yp*) [with _Yp = unsigned char; <template-parameter-2-2> = void; _Tp = unsigned char]’ at /usr/include/c++/13/bits/shared_ptr.h:214:46, inlined from ‘void Wav::readWavBuffer(std::istream&)’ at /home/sever-in/vibra/fingerprinting/audio/wav.cpp:128:26: /usr/include/c++/13/bits/shared_ptr_base.h:921:15: warning: ‘void operator delete(void*)’ called on pointer returned from a mismatched allocation function [-Wmismatched-new-delete] 921 | delete __p; | ^~~~~~~~~~ /home/sever-in/vibra/fingerprinting/audio/wav.cpp: In member function ‘void Wav::readWavBuffer(std::istream&)’: /home/sever-in/vibra/fingerprinting/audio/wav.cpp:128:77: note: returned from ‘void* operator new [](std::size_t)’ 128 | mData = std::shared_ptr<std::uint8_t>(new std::uint8_t[mDataSize]); | ^ [ 87%] Building CXX object CMakeFiles/vibra.dir/communication/shazam.cpp.o [100%] Linking CXX executable vibra [100%] Built target vibra

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.