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.
Requirements
- Python3
- PyAudio
- NumPy
- SciPy
Installation
option A:
- install from the official pypi package (might be outdated):
pip install clap-detector
option B:
-
Install the required Python packages:
pip install pyaudio numpy scipy
-
Clone the repository:
git clone https://github.com/TzurSoffer/clapDetection/ cd clapDetection/src/clapDetector
-
Run the clap detection script:
python clapDetector.py
Configuration
- Adjust parameters in the
ClapDetector
class constructor to fine-tune the clap detection system.
Usage
-
Create a script that uses this library
import logging from clapDetector import ClapDetector 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: print(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()
-
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
Built Distribution
File details
Details for the file clap-detector-2.0.4.tar.gz
.
File metadata
- Download URL: clap-detector-2.0.4.tar.gz
- Upload date:
- Size: 8.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 326a112389db2ee386a0c6dc8e15f47e1a7019985cc6910ad261757fd726de16 |
|
MD5 | 22f0e1d96a1ca009f5f5b310c64326ce |
|
BLAKE2b-256 | c896c207e8be3f79bb704025cc5b1e3a85dd64b2defc6b65bf8d78a5a0ae3845 |
File details
Details for the file clap_detector-2.0.4-py3-none-any.whl
.
File metadata
- Download URL: clap_detector-2.0.4-py3-none-any.whl
- Upload date:
- Size: 8.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 96432a84ad8b49c17c06fb458cd2c258a4ffef59c64f2d61760fad82e41c570d |
|
MD5 | e55a42977cafdb3d50f658942d8f87f3 |
|
BLAKE2b-256 | 4470ccdbe88be8fd2890de72f35f97829da840e07f73634107a24a52d273aad2 |