Skip to main content

A clap detector that can detect claps in patterns of single, double, etc.

Project description

Clap Detection System

Overview

This project implements a clap detection system using an a mic or raw audio data as input. It can detect calp patterns including single and double claps.

Features

  • Clap pattern detection.
  • Dynamic threshold adjustment for robust clap detection.
  • Bandpass filtering to focus on clap frequencies.
  • Audio recording and saving capabilities.

Requirements

  • Python3
  • PyAudio
  • NumPy
  • SciPy

Installation

option A:

  1. install from the official pypi package (might be outdated):
    pip install clap-detector
    

option B:

  1. Install the required Python packages:

    pip install pyaudio numpy scipy
    
  2. Clone the repository:

    git clone https://github.com/TzurSoffer/clapDetection/
    cd clapDetection/src
    
  3. Run the clap detection script:

    python clapDetector.py
    

Configuration

  • Adjust parameters in the ClapDetector class constructor to fine-tune the clap detection system.

Usage

  1. Create a script that uses this library

     pyaudio.PyAudio()
     thresholdBias = 6000
     lowcut=200               #< increase this to make claps detection more strict
     highcut=3200             #< decrease this to make claps detection more strict
     clapDetector = ClapDetector(logLevel=logging.DEBUG, inputDeviceIndex="USB Audio Device")
     clapDetector.printDeviceInfo()
     print("""
           -----------------------------
           These are the audio devices, find the one you are using and change the variable "inputDeviceIndex" to the the name or index of your audio device. Then restart the program and it should properly get audio data.
           -----------------------------
           """)
     clapDetector.initAudio()
    
     try:
         while True:
             audioData = clapDetector.getAudio()
    
             result = clapDetector.run(thresholdBias=thresholdBias, lowcut=lowcut, highcut=highcut, audioData=audioData)
             resultLength = len(result)
             if resultLength == 2:
                 message = f"Double clap detected! bias {thresholdBias}, lowcut {lowcut}, and highcut {highcut}"
                 clapDetector.saveAudio(folder="./")
    
     except KeyboardInterrupt:
         print("Exited gracefully")
     except Exception as e:
         print(f"error: {e}")
         clapDetector.stop()
    
  2. The system will continuously monitor audio input and detect claps.

Troubleshooting

  • If there are issues with audio input, check the device index in the ClapDetector constructor.

  • Adjust the bandpass filter parameters for better clap detection in different environments.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

clap-detector-2.0.2.tar.gz (8.4 kB view details)

Uploaded Source

Built Distribution

clap_detector-2.0.2-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file clap-detector-2.0.2.tar.gz.

File metadata

  • Download URL: clap-detector-2.0.2.tar.gz
  • Upload date:
  • Size: 8.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.0.0 CPython/3.12.1

File hashes

Hashes for clap-detector-2.0.2.tar.gz
Algorithm Hash digest
SHA256 103f52edd3ff6f83033edc2c1905161434801c0a908bfda4786601ac0279d35c
MD5 2765852ca7adfbc61f5ed59e857808ee
BLAKE2b-256 6fce1ce311f7437525e10701b147bc40e54f0919c95f5363c16b327201bca9c0

See more details on using hashes here.

File details

Details for the file clap_detector-2.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for clap_detector-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3cc5ea544893963e1bd21a0880ce619a809d2684d3852174aadff1a0fb7d7be6
MD5 efb7eb432786ecf39a8ec928205747c0
BLAKE2b-256 0540d568c6f8d9c0da50f5402bf991d5b8dd1b6febaa5c7ccf1b267ec749d370

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page