Documentation¶
Listener Module¶
-
class
piclap.Listener(config=None, calibrate=True)[source]¶ Describes methods which are called by user for the initialisation of the PyAudio module to stream microphone input.
- Parameters
- Variables
config (class: Settings) – Store the Settings object
input (class: pyaudio.PyAudio) – Store the PyAudio object
stream (class: pyaudio.Stream) – Open a new input audio stream and store the stream object
claps (int) – Store current value of claps counted and initially set to 0
lock (thread.lock) – Store the thread lock
processor (class: SignalProcessor) – Store the Processor object
-
clapWait(clap)[source]¶ Start waiting for a small duration of time recursively until no more new claps are detected
- Parameters
clap (int) – Number of claps found at the time of wait initialised
-
claps¶ default:
0This class property contains the current count of claps detected
-
device¶ Stores an
Deviceobject which initialisePyAudiowith calibration and manages the audio interface
-
listenClaps(threadName)[source]¶ This method runs on a child thread with
lockwhenclapsequals1and reset the class propertyclapsto0when execution is finished- Parameters
threadName (str) – Name of the child thread started
-
processor¶ Initialised with an
SignalProcessorobject using the signal processing method found insideconfig
-
start()[source]¶ When this method is called, the listener start reading binary data from stream and sreach for claps inside the chunks of data using
SignalProcessoruntilSettings.exitflag isTrue- Raises
KeyboardInterrupt: If Control + C is pressed on keyboard
Settings Module¶
-
class
piclap.Settings[source]¶ This class describes all the configurations needed for the
Listenerto work.- Variables
exit (boolean) – Exit flag the determine the exit state of
Listenerrate (int) – Bitrate at which input audio is streamed
chunk_size (int) – Frame count inside the audio buffer
wait (float) – Clap wait in seconds
method (class: Munch) – The algorithm used for the detection of claps
actions (list(str)) – Collection of defined actions
-
actions¶ 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
Condition: The method name defined should start with ‘on’ and end with ‘Claps’ with the clap count inbetween them.
-
channels¶ default:
1(Mono Channel)Number of audio channel to listen
-
chunk_size¶ default:
1024Number of frames in the input audio buffer
-
exit¶ default:
FalseExit flag
-
method¶ default:
{'name': 'threshold','value': 7000}Detection method used for identifing claps
-
on4Claps()[source]¶ Action performed when 4 claps are detected. As default,
exitflag is set toTrueif 4 claps are detected
-
rate¶ default:
44100Number of audio samples collected in 1 second
-
updateMethod(method)[source]¶ Update the method for detecting clap
- Parameters
method (dict) – A dict type parameter which defines a clap detection method
-
wait¶ default:
0.5Time duration to wait for claps to complete in
Listener.clapWait()
SignalProcessor Module¶
-
class
piclap.SignalProcessor(method)[source]¶ Describes all the signal processing algorithms and selector method.
- Parameters
method (class: Munch) – An object that contain the configuration and details of which algorithm to be used for processing the data received.
- Variables
-
alg_id¶ default:
0Search for the algorithm name in the
DETECTION_ALGORITHMSand store the id found
-
algorithm¶ The algorithm stored in this variable is used throughout the execution
-
findClap(data)[source]¶ Based on the detection algorithm selected, the data is given to the selected algorithm
- Parameters
data (bytearray) – Binary data received from microphone
- Returns
True if clap is detected, False otherwise
- Return type
bool
-
useFFT(byte_stream)[source]¶ This algorithm is not implemented yet
- Parameters
byte_stream (bytearray) – Binary stream of data received from microphone
-
useFiter(byte_stream)[source]¶ This algorithm is not implemented yet
- Parameters
byte_stream (bytearray) – Binary stream of data received from microphone
-
useThreshold(byte_stream)[source]¶ This algorithm uses a threshold value to detect claps.
- Parameters
byte_stream (bytearray) – Binary stream of data received from microphone
- Returns
When the maximum value of the integer array is greater than threshold, it returns True and False if otherwise
- Return type
bool
Device Module¶
-
class
piclap.Device(config, calibrate)[source]¶ Describes methods which are called by user for the initialisation of the PyAudio module to stream microphone input.
- Parameters
- Variables