Giter Club home page Giter Club logo

knock's Introduction

This is a tool for recognizing audio "secret knocks". Usage is something
like:

  1. Record a knock. You can use any program you like, or even pipe
     directly into "listen" in step 2, though keeping a copy is handy if
     you want to be able to teach anybody your knock. The "trim" here
     just limits the recording length; you don't need to trim silence
     yourself.

       $ rec knock.mp3 trim 0 5

  2. Compute the knock times using the "listen" tool. Weirdly sox
     doesn't seem to handle mp3 over stdin, hence the conversion here.

       $ sox knock.mp3 -t wav - | ./listen
       0.812500
       1.593750
       2.343750
       2.718750
       --

  2. Check for similar knocks by feeding a live recording into "listen",
     which finds knocks, and then check for matches using knock.pl. Note
     that even though our desired knock doesn't start at t=0, all times
     will be normalized against the first knock (so the first knock of
     an attempt always starts at the same time as the first knock of the
     match).

     A match is found if we saw the same number of knocks (followed by
     at least 1.5s of silence to indicate the end of the sequence), and
     if the timing of the knocks is close-ish (based on some arbitrary
     scoring heuristic) to the desired sequence.

       rec -q -t wav - |
       ./listen |
       perl knock.pl 0.8125 1.59375 2.34375 2.71875 |
       while read r; do
         case "$r" in
         ok)
                play -q bell.mp3
                ;;
         *)
                play -q buzzer.mp3
                ;;
         esac
       done

There are a lot of heuristics and magic numbers in various programs:

  - the "listen" program breaks time into 2000-sample chunks (sox seems
    to default to 2 channels, 32000Hz, so that's about 31ms). It
    computes the "energy" for a chunk by looking for noise; anything
    over a certain cutoff is counted as a knock. That cutoff is
    hard-coded and just a guess (too low and you get noise counting as a
    knock; too high and you miss a knock).

  - the amount of silence to end a sequence is hard-coded to 1.5s.
    Shortening this makes the program more responsive (since it has to
    wait to decide the sequence is done) at the risk of cutting off
    knocks that come after long pauses.

  - the scoring heuristic in knock.pl is the sum of squares of the
    differences between each knock's time, with an arbitrary cutoff of
    0.05 (which is not unit-less; we're ultimately comparing seconds).

These could probably use some tweaking, but it seems to work OK in
practice for my setup.

knock's People

Contributors

peff avatar

Watchers

 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.