Installation

Install Dependencies

Debian/Ubuntu/Rasberry Pi OS

sudo apt-get update && sudo apt-get upgrade -y
sudo apt-get install -y python3-pip portaudio19-dev

Fedora

sudo dnf upgrade --refresh
sudo dnf install -y python3-pip portaudio-devel redhat-rpm-config

Centos

# CentOS 8
sudo dnf upgrade --refresh
sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

# CentOS 7
yum -y update
rpm -Uvh https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm

# CentOS 6
yum -y update
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm

sudo yum install -y python37-pip portaudio portaudio-devel

MacOS

brew install python3 portaudio
python3 -m pip install --user pyaudio || python3 -m pip install --user --global-option='build_ext' --global-option='-I/usr/local/include' --global-option='-L/usr/local/lib' pyaudio

Install pi-clap

Using Git

git clone https://github.com/nikhiljohn10/pi-clap
cd pi-clap
make local-install
make run

make local-install is a helpful tool for alpha/beta testing before deploying to PyPi server

Using Pip

python3 -m pip install --user pi-clap

Use the module as it is given in the example below.

Using pi-clap

Writing an app using pi-clap is only 3 lines it need ideally.

1
2
3
4
5
6
#!/usr/bin/python3

from piclap import *

listener = Listener()
listener.start()

But this is not the real world senario. You will need more control over the settings that match your microphone and operating system. Following code give your more flexibility.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/python3

import os
import sys
sys.path.append(os.path.abspath('.'))

from piclap import *


class Config(Settings):
    '''Describes custom configurations and action methods to be executed based
    on the number of claps detected.
    '''

    def __init__(self):
        Settings.__init__(self)
        self.method.value = 10000

    def on2Claps(self):
        '''Custom action for 2 claps'''
        print("Light flashed on pin 4")

    def on3Claps(self):
        '''Custom action for 3 claps'''
        print("Light toggled on pin 6")


def main():
    config = Config()
    listener = Listener(config=config, calibrate=False)
    listener.start()


if __name__ == '__main__':
    main()