iot-logic/src/sensor/soundsensor.py

35 lines
1015 B
Python
Raw Normal View History

2020-08-24 20:38:38 +02:00
#!/usr/bin/env python3
2020-09-30 03:35:20 +02:00
from typing import Optional
2020-08-24 20:38:38 +02:00
from .abcsensor import AbcSensor
2020-09-30 03:35:20 +02:00
from utils import config
from birbnetes_iot_platform_raspberry import BirbnetesIoTPlatformRecordDriver
2020-08-24 20:38:38 +02:00
"""
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.
"""
2020-09-30 03:35:20 +02:00
def __init__(self):
2020-09-30 04:56:17 +02:00
BirbnetesIoTPlatformRecordDriver.init(config.SAMPLE_LENGTH, microphone=config.RECORD_DEVICE)
2020-09-30 03:35:20 +02:00
def getvalue(self) -> Optional[str]:
2020-08-24 20:38:38 +02:00
"""
2020-09-30 03:35:20 +02:00
Retrieve a configurable length second sound clip from a microphone.
2020-08-24 20:38:38 +02:00
:return:
"""
2020-09-30 03:35:20 +02:00
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()