Files
iot-logic/src/sensor/soundsensor.py
marcsello 9a6852c2c0
All checks were successful
continuous-integration/drone/push Build is passing
Sound device is now configurable
2020-09-30 04:56:17 +02:00

35 lines
1015 B
Python

#!/usr/bin/env python3
from typing import Optional
from .abcsensor import AbcSensor
from utils import config
from birbnetes_iot_platform_raspberry import BirbnetesIoTPlatformRecordDriver
"""
Sound sensor high level API
"""
__author__ = "@tormakris"
__copyright__ = "Copyright 2020, Birbnetes Team"
__module_name__ = "soundsensor"
__version__text__ = "1"
class SoundSensor(AbcSensor):
"""
SoundSensor class. Responsible for sound retrieval from any microphones present.
"""
def __init__(self):
BirbnetesIoTPlatformRecordDriver.init(config.SAMPLE_LENGTH, microphone=config.RECORD_DEVICE)
def getvalue(self) -> Optional[str]:
"""
Retrieve a configurable length second sound clip from a microphone.
:return:
"""
return BirbnetesIoTPlatformRecordDriver.get_recording(False)
def __del__(self):
# In theory you should not put anything to __del__ as it is not guaranteed to be called.
BirbnetesIoTPlatformRecordDriver.cleanup()