Skip to content

Commit

Permalink
Merge pull request #40 from nikhiljohn10/master
Browse files Browse the repository at this point in the history
v1.3.1
  • Loading branch information
nikhiljohn10 committed Aug 28, 2020
2 parents 7443386 + b510407 commit aee00e2
Show file tree
Hide file tree
Showing 24 changed files with 403 additions and 306 deletions.
80 changes: 1 addition & 79 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,85 +47,7 @@ A python package for clap detection

( Try 2 claps to activate the output line for 1 sec and 3 claps to toggle ON/OFF state of given PIN. Note: Use 4 claps to exit from the system )

### Installing dependencies for other operating systems

```
# Debian based OS like Ubuntu
sudo apt-get install -y python3-pip portaudio19-dev
```

```
# Fedora
sudo dnf install -y python3-pip portaudio-devel redhat-rpm-config
pip3 install --user pyaudio
```

```
# Centos
sudo dnf install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm # CentOS 8
rpm -Uvh https://dl.fedoraproject.org/pub/epel/7/x86_64/Packages/e/epel-release-7-11.noarch.rpm # CentOS 7
rpm -Uvh http://download.fedoraproject.org/pub/epel/6/x86_64/epel-release-6-8.noarch.rpm # CentOS 6
sudo yum install -y python37-pip portaudio portaudio-devel
pip3 install pyaudio
```

```
# MacOS
brew install portaudio
pip3 install pyaudio munch || pip3 install --global-option='build_ext' --global-option='-I/usr/local/include' --global-option='-L/usr/local/lib' pyaudio munch
```

### Example code

```
# Example code for using the package
from piclap import Listener, Settings
class Config(Settings):
'''This is an user defined derived class with `piclap.Settings` as base class'''
def __init__(self):
'''Defines new and override existing properties here'''
self.chunk_size = 512 # Reduce as power of 2 if pyaudio overflow
self.interval = 0.5 # Adjust interval between claps
self.method.value = 300 # Threshold value adjustment
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)
config = Config()
listener = Listener(config)
listener.start()
```

### Using Pip package

```
# Using the following command in terminal
pip3 install pi-clap
```

### Using Git Clone
```
git clone https://github.com/nikhiljohn10/pi-clap
cd pi-clap
python3 ./example/app.py
```
##### Visit Official documentation @ [pi-clap.nikz.in](https://pi-clap.nikz.in/getting-started.html)

### License

Expand Down
2 changes: 1 addition & 1 deletion docs/.buildinfo
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Sphinx build info version 1
# This file hashes the configuration used when building these files. When it is not found, a full rebuild will be done.
config: 3170068174795e34d5b5a5d41032d3be
config: 7aea4f226f698ea442cec4a461fc4fe6
tags: 645f666f9bcd5a90fca523b33c5a78b7
2 changes: 1 addition & 1 deletion docs/_modules/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Overview: module code &mdash; Pi Clap 1.3 documentation</title>
<title>Overview: module code &mdash; Pi Clap 1.3.1 documentation</title>



Expand Down
2 changes: 1 addition & 1 deletion docs/_modules/piclap/_listener.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>piclap._listener &mdash; Pi Clap 1.3 documentation</title>
<title>piclap._listener &mdash; Pi Clap 1.3.1 documentation</title>



Expand Down
2 changes: 1 addition & 1 deletion docs/_modules/piclap/_processor.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>piclap._processor &mdash; Pi Clap 1.3 documentation</title>
<title>piclap._processor &mdash; Pi Clap 1.3.1 documentation</title>



Expand Down
44 changes: 18 additions & 26 deletions docs/_modules/piclap/_settings.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>piclap._settings &mdash; Pi Clap 1.3 documentation</title>
<title>piclap._settings &mdash; Pi Clap 1.3.1 documentation</title>



Expand Down Expand Up @@ -166,28 +166,22 @@ <h1>Source code for piclap._settings</h1><div class="highlight"><pre>


<div class="viewcode-block" id="Settings"><a class="viewcode-back" href="../../piclap.html#piclap.Settings">[docs]</a><span class="k">class</span> <span class="nc">Settings</span><span class="p">:</span>
<span class="sd">&quot;&quot;&quot;This class describes all the configurations needed for the :class:`piclap.Listener` to work.</span>

<span class="sd"> :param controller: A :class:`piclap.Controller` object, defaults to None</span>
<span class="sd"> :type controller: class: `piclap.Controller`</span>
<span class="sd"> :var controller: Holds the controller object passed as argument</span>
<span class="sd"> :vartype controller: class: `piclap.Controller`</span>
<span class="sd"> :var boolean exit: Holds the controller object passed as argument</span>
<span class="sd"> :var int rate: Holds the controller object passed as argument</span>
<span class="sd"> :var int channels: Holds the controller object passed as argument</span>
<span class="sd"> :var int chunk_size: Holds the controller object passed as argument</span>
<span class="sd"> :var float interval: Holds the controller object passed as argument</span>

<span class="sd"> :var method: Holds the controller object passed as argument</span>
<span class="sd"> :vartype method: class: `piclap.Controller`</span>
<span class="sd"> :var actions: Holds the controller object passed as argument</span>
<span class="sd"> :vartype actions: class: `piclap.Controller`</span>
<span class="sd">&quot;&quot;&quot;This class describes all the configurations needed for the :class:`Listener` to work.</span>

<span class="sd"> :var boolean exit: Exit flag the determine the exit state of :class:`Listener`</span>
<span class="sd"> :var int rate: Bitrate at which input audio is streamed</span>
<span class="sd"> :var int channels: Number of audio channels used by :class:`Listener`</span>
<span class="sd"> :var int chunk_size: Frame count inside the audio buffer</span>
<span class="sd"> :var float interval: Clap interval in seconds</span>

<span class="sd"> :var method: The algorithm used for the detection of claps</span>
<span class="sd"> :vartype method: class: `Munch`</span>
<span class="sd"> :var actions: Collection of defined actions</span>
<span class="sd"> :vartype actions: list(str)</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">controller</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
<span class="k">def</span> <span class="fm">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Constructor method&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">controller</span> <span class="o">=</span> <span class="n">controller</span> <span class="c1"># Updated docs</span>
<span class="sd">&quot;&quot;&quot;If the :attr:`controller` parameter is ``None``, an object of :class:`piclap.Controller` is assigned&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">exit</span> <span class="o">=</span> <span class="kc">False</span>
<span class="sd">&quot;&quot;&quot;**default:** ``False``</span>

Expand All @@ -208,7 +202,7 @@ <h1>Source code for piclap._settings</h1><div class="highlight"><pre>
<span class="bp">self</span><span class="o">.</span><span class="n">interval</span> <span class="o">=</span> <span class="mf">0.5</span>
<span class="sd">&quot;&quot;&quot;**default:** ``0.5``</span>

<span class="sd"> Time duration to wait inside :meth:`piclap.Listener.clapWait()`&quot;&quot;&quot;</span>
<span class="sd"> Time duration to wait inside :meth:`Listener.clapWait()`&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">method</span> <span class="o">=</span> <span class="n">Objectify</span><span class="o">.</span><span class="n">fromDict</span><span class="p">({</span>
<span class="s1">&#39;name&#39;</span><span class="p">:</span> <span class="s1">&#39;threshold&#39;</span><span class="p">,</span>
<span class="s1">&#39;value&#39;</span><span class="p">:</span> <span class="mi">7000</span>
Expand All @@ -220,17 +214,15 @@ <h1>Source code for piclap._settings</h1><div class="highlight"><pre>
<span class="s1">&#39;on&#39;</span><span class="p">)</span> <span class="ow">and</span> <span class="n">m</span><span class="o">.</span><span class="n">endswith</span><span class="p">(</span><span class="s1">&#39;Claps&#39;</span><span class="p">)]</span>
<span class="sd">&quot;&quot;&quot;When the class initialised, it collects all the actions defined inside this class as well as any classes where are derived with this class as base class</span>

<span class="sd"> **Condition:** __The method name defined should start with &#39;on&#39; and end with &#39;Claps&#39; with the clap count inbetween them.__</span>
<span class="sd"> **Condition:** *The method name defined should start with &#39;on&#39; and end with &#39;Claps&#39; with the clap count inbetween them.*</span>
<span class="sd"> &quot;&quot;&quot;</span>

<div class="viewcode-block" id="Settings.on2Claps"><a class="viewcode-back" href="../../piclap.html#piclap.Settings.on2Claps">[docs]</a> <span class="k">def</span> <span class="nf">on2Claps</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Action performed when 2 claps are detected. As default, it call the method :meth:`piclap.Controller.flashLight` on pin 13&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">pi</span><span class="o">.</span><span class="n">flashLight</span><span class="p">(</span><span class="n">pin</span><span class="o">=</span><span class="mi">13</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;Action performed when 2 claps are detected. As default, it call the method :meth:`Controller.flashLight` on pin 13&quot;&quot;&quot;</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Flashed light&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Settings.on3Claps"><a class="viewcode-back" href="../../piclap.html#piclap.Settings.on3Claps">[docs]</a> <span class="k">def</span> <span class="nf">on3Claps</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
<span class="sd">&quot;&quot;&quot;Action performed when 3 claps are detected. As default, it call the method :meth:`piclap.Controller.toggleLight` on pin 24&quot;&quot;&quot;</span>
<span class="bp">self</span><span class="o">.</span><span class="n">pi</span><span class="o">.</span><span class="n">toggleLight</span><span class="p">(</span><span class="n">pin</span><span class="o">=</span><span class="mi">24</span><span class="p">)</span>
<span class="sd">&quot;&quot;&quot;Action performed when 3 claps are detected. As default, it call the method :meth:`Controller.toggleLight` on pin 24&quot;&quot;&quot;</span>
<span class="nb">print</span><span class="p">(</span><span class="s2">&quot;Toggled light&quot;</span><span class="p">)</span></div>

<div class="viewcode-block" id="Settings.on4Claps"><a class="viewcode-back" href="../../piclap.html#piclap.Settings.on4Claps">[docs]</a> <span class="k">def</span> <span class="nf">on4Claps</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
Expand Down
36 changes: 14 additions & 22 deletions docs/_sources/getting-started.rst.txt
Original file line number Diff line number Diff line change
Expand Up @@ -72,30 +72,22 @@ Using Pip package
Example code
------------

.. code-block::
Writing an app using Pi Clap is only 3 lines it need ideally.

from piclap import Listener, Settings
.. literalinclude:: ../../example/app.py
:language: python
:linenos:

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.

class Config(Settings):
'''This is an user defined derived class with `piclap.Settings` as base class'''
.. literalinclude:: ../../example/advanced.app.py
:language: python
:emphasize-lines: 6-23,26-28,32-33
:linenos:

def __init__(self):
'''Defines new and override existing properties here'''
self.chunk_size = 512 # Reduce as power of 2 if pyaudio overflow
self.interval = 0.5 # Adjust interval between claps
self.method.value = 300 # Threshold value adjustment
If you are using **Raspberry Pi**, use following code:

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)
config = Config()
listener = Listener(config)
listener.start()
If you are using **Raspberry Pi**, use the extended version of this example: `app.py <https://github.com/nikhiljohn10/pi-clap/blob/master/example/app.py>`_
.. literalinclude:: ../../example/rpi.app.py
:language: python
:emphasize-lines: 4,7-20,30,37-38,43,45-47
:linenos:
2 changes: 1 addition & 1 deletion docs/_static/documentation_options.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
var DOCUMENTATION_OPTIONS = {
URL_ROOT: document.getElementById("documentation_options").getAttribute('data-url_root'),
VERSION: '1.3',
VERSION: '1.3.1',
LANGUAGE: 'en',
COLLAPSE_INDEX: false,
BUILDER: 'html',
Expand Down
8 changes: 3 additions & 5 deletions docs/genindex.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>Index &mdash; Pi Clap 1.3 documentation</title>
<title>Index &mdash; Pi Clap 1.3.1 documentation</title>



Expand Down Expand Up @@ -199,16 +199,14 @@ <h2 id="C">C</h2>
<li><a href="piclap.html#piclap.Settings.channels">channels (piclap.Settings attribute)</a>
</li>
<li><a href="piclap.html#piclap.Settings.chunk_size">chunk_size (piclap.Settings attribute)</a>
</li>
<li><a href="piclap.html#piclap.Listener.claps">claps (piclap.Listener attribute)</a>
</li>
</ul></td>
<td style="width: 33%; vertical-align: top;"><ul>
<li><a href="piclap.html#piclap.Listener.claps">claps (piclap.Listener attribute)</a>
</li>
<li><a href="piclap.html#piclap.Listener.clapWait">clapWait() (piclap.Listener method)</a>
</li>
<li><a href="piclap.html#piclap.Listener.config">config (piclap.Listener attribute)</a>
</li>
<li><a href="piclap.html#piclap.Settings.controller">controller (piclap.Settings attribute)</a>
</li>
</ul></td>
</tr></table>
Expand Down

0 comments on commit aee00e2

Please sign in to comment.