Giter Site home page Giter Site logo

graystripe17 / sadzam Goto Github PK

View Code? Open in Web Editor NEW
0.0 2.0 0.0 150.16 MB

A sad version of the Shazam algorithm, implemented in Python

Python 95.70% Shell 0.01% HTML 0.12% CSS 0.02% JavaScript 0.08% Jupyter Notebook 2.79% C++ 0.39% C 0.71% Fortran 0.05% Makefile 0.01% MATLAB 0.01% TeX 0.12%

sadzam's Introduction

Sadzam

A slow version of the Shazam algorithm implemented in Python.

Why

This algorithm is extremely elegant in my opinion. It starts with the simple question "How do you search audio?" But it must also handle noise, use a short sample, and be lightning fast.

The algorithm solves these through filtering, windowing, and FFTs to generate an audio fingerprint.

Importantly, it doesn't use neural nets or "machine learning".

Algorithm

  1. Read in audio file
  2. Convert from stereo to mono
  3. Low pass filter (butterworth)
  4. Downsample
  5. Hamming window in 0.1s intervals
  6. FFT and sort into (logarithmic) bins
  7. Save "loudest" frequencies into spectrogram
  8. Create ordering of points
  9. For each "target" point, calc distance from neighboring cluster
  10. Save as keys in dict pointing to songID
  11. Normalize results, count matches

Considerations

  1. Use whatever window besides rectangular to prevent spectral leakage
  2. The frequency response of the human ear is highest at 3000Hz. We split it up into 6 different frequency bins
  3. We take the magnitude of the frequency
  4. Complexity cannot scale up with size of database. You can't just do cross correlation

Visualization

windowed magnitude spectrogram

Running the tests

pytest

Demo

  1. Add about 50 songs to the database folder
  2. Convert songs to wav using ffmpeg
  3. Build database
  4. Obtain 10 second sample (noise optional)
  5. Create frequencies array, spectrogram
  6. Count hits, make pairs
  7. Analyze hits

The following output correctly identifies oblivion sample + noise

[(('oblivion', 'lilypotter'), 0.02227589908749329),
 (('ijustcalledtosayiloveyou', 'steviewonder'), 0.016269960831575777),
 (('jessiesgirl', 'rickspringfield'), 0.011674641148325358),
 (('canttakemyeyesoffofyou', 'frankievalli'), 0.010076185795035636),
 (('ilikethat', 'janellemonae'), 0.009678668215253582)]

Acknowledgments

sadzam's People

Contributors

graystripe17 avatar

Watchers

 avatar  avatar

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.