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.
Troubleshooting
PyAudio
-
Option A
If clap-detector fails to install due to pyaudio issues, try to installportaudio19
usingsudo apt install portaudio19-dev
, then install clap-detector normally usingpip install clap-detector
. -
Option B
If pyaudio still fails to install after trying option A, try to install it usingsudo apt install python3-pyaudio
, then install clap-detector normallypip install clap-detector
.
Input
- If there are issues with audio input, check the device index 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:
- install from the official pypi package:
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
option A:
-
clone the repository, if you have not already using
git clone https://github.com/TzurSoffer/clapDetection/
-
go into the examples folder and choose one of the scripts you would like to run.
option B:
-
Create a script that uses this library
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.
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.5.tar.gz
.
File metadata
- Download URL: clap_detector-2.0.5.tar.gz
- Upload date:
- Size: 10.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7390b5b2887cf73fec7190ec22c2e5edbcafd879668604edf021877acfab68d8 |
|
MD5 | 1ecccf9a1c1f36e46e75f8264c211db5 |
|
BLAKE2b-256 | e5f47f94982db686f56c6a3162c377e43823218a1c9392bab5189421073bb515 |
File details
Details for the file clap_detector-2.0.5-py3-none-any.whl
.
File metadata
- Download URL: clap_detector-2.0.5-py3-none-any.whl
- Upload date:
- Size: 9.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.11.1
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 45442b4191b28a1d6641d703258e8743fdd8c875065afc07835602264e5e66e7 |
|
MD5 | 90a58de48b6ea7e39443de4624a20a2a |
|
BLAKE2b-256 | 1b2638be0e42998b2cc9135d16b4692e70f760c53d8aebfb5710ad05d8a264d3 |