iot-logic/src/sensor/soundsensor.py

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()