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 clap 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. Live Visualization Failed to load

Troubleshooting

PyAudio

  • Option A

    If clap-detector fails to install due to pyaudio issues, try to install portaudio19 using sudo apt install portaudio19-dev, then install clap-detector normally using pip install clap-detector.
  • Option B

    If pyaudio still fails to install after trying option A, try to install it using sudo apt install python3-pyaudio, then install clap-detector normally pip install clap-detector.

Input

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

Accuracy

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

Requirements

  • Python3
  • PyAudio
  • NumPy
  • SciPy

Installation

option A:

  1. install from the official pypi package:
    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/clapDetector
    
  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

option A:

  1. clone the repository, if you have not already using git clone https://github.com/TzurSoffer/clapDetection/

  2. go into the examples folder and choose one of the scripts you would like to run.

option B:

  1. Create a script that uses this library

    import time
    from clapDetector import ClapDetector, printDeviceInfo
    
    print("""
          --------------------------------
          The application initially attempts to use the system's default audio device. If this doesn't work or if you prefer to use a different device, you can change it. Below are the available audio devices. Find the one you are using and change the 'inputDevice' variable to the name or index of your preferred audio device. Then, restart the program, and it should properly capture audio.
          --------------------------------
          """)
    printDeviceInfo()
    
    thresholdBias = 6000
    lowcut=200               #< increase this to make claps detection more strict 
    highcut=3200             #< decrease this to make claps detection more strict
    clapDetector = ClapDetector(inputDevice=-1, logLevel=10)
    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:
                print(f"Double clap detected! bias {thresholdBias}, lowcut {lowcut}, and highcut {highcut}")
                clapDetector.saveAudio(folder="./")
          time.sleep(1/60)
    
    except KeyboardInterrupt:
       print("Exited gracefully")
    except Exception as e:
       print(f"error: {e}")
    finally:
       clapDetector.stop()
    
  2. The system will continuously monitor audio input and detect claps.

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.6.tar.gz (10.9 kB view details)

Uploaded Source

Built Distribution

clap_detector-2.0.6-py3-none-any.whl (10.0 kB view details)

Uploaded Python 3

File details

Details for the file clap_detector-2.0.6.tar.gz.

File metadata

  • Download URL: clap_detector-2.0.6.tar.gz
  • Upload date:
  • Size: 10.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.6

File hashes

Hashes for clap_detector-2.0.6.tar.gz
Algorithm Hash digest
SHA256 a7b6db97386942a4351630829cad7a6c32aca47d025c082f8faa28c6f0abd316
MD5 80ecf9e9f8ddfc8ccb9d2b30dbd7deb4
BLAKE2b-256 eea84d9f1c385502962e664a401e10e6d4737a8ff8451e180cd3d29d4e7323cc

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for clap_detector-2.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 7326b059ac8a05649df7a777244b44d01c53816fce265aa1e6a6554775581c65
MD5 06618c96d56f3d82052f6a1d4d195019
BLAKE2b-256 e5dbabb768d5cf0e520fe49f0b8c31d2acb5176751947153db90cce594b4ff11

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