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:
- 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
-
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
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()
-
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.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 103f52edd3ff6f83033edc2c1905161434801c0a908bfda4786601ac0279d35c |
|
MD5 | 2765852ca7adfbc61f5ed59e857808ee |
|
BLAKE2b-256 | 6fce1ce311f7437525e10701b147bc40e54f0919c95f5363c16b327201bca9c0 |
File details
Details for the file clap_detector-2.0.2-py3-none-any.whl
.
File metadata
- Download URL: clap_detector-2.0.2-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 | 3cc5ea544893963e1bd21a0880ce619a809d2684d3852174aadff1a0fb7d7be6 |
|
MD5 | efb7eb432786ecf39a8ec928205747c0 |
|
BLAKE2b-256 | 0540d568c6f8d9c0da50f5402bf991d5b8dd1b6febaa5c7ccf1b267ec749d370 |