/vibra

🎵 C++ Cross Platform Shazam Client that creates a fingerprint from a music file to retrieve song information

Primary LanguageC++GNU General Public License v3.0GPL-3.0


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.
  • 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!

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 ✅

Run 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:
    • libcurl: To send HTTP requests to the Shazam API.
    • libfftw3: To calculate the Fast Fourier Transform.

Build

  • You can build vibra with CMake using the following commands:

    • mkdir build && cd build
    • cmake ..
    • make
  • If you want to specify the paths for libraries or include files, you can use the commands below:

    • cmake -DINCLUDE_PATH=/path/to/include
    • cmake -DLIBRARY_PATH=/path/to/lib

Run

  • Use ./vibra help to see the help message.
Usage: vibra <action> <param>

* Actions:
	fingerprint-from-raw-pcm <audio_chunk_seconds>
		Generate fingerprint from raw PCM (s16le, mono, 16kHz) via stdin.

	fingerprint-from-wav-file <wav_file_path>
		Generate fingerprint from wav file

	recognize-song-from-raw-pcm <audio_chunk_seconds>
		Recognize song from raw PCM (s16le, mono, 16kHz) via stdin.

	recognize-song-from-wav-file <wav_file_path>
		Recognize song from wav file

Examples

- recognizing song from wav file
$ ./vibra recognize-song-by-file "stairway_to_heaven.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 16 -e signed-integer -r 16000 -c 1 - 2>/dev/null | ./vibra recognize-song-from-raw-pcm 5 > 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)",
  "",
  "All them other niggas lame, and you know it now",
...

WebAssembly Version Support

License

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