Updated static interface

This commit is contained in:
Pünkösd Marcell 2020-09-30 03:12:25 +02:00
parent 4bf5d980d2
commit 087395e950
3 changed files with 30 additions and 9 deletions

View File

@ -93,3 +93,7 @@ class BirbnetesIoTPlatformStatusDriver:
@classmethod
def enqueue_pattern(cls, target: str, pattern: list):
cls.blinken_lights.enqueue_pattern(target, pattern)
@classmethod
def cleanup(cls):
cls.blinken_lights.stop()

View File

@ -10,3 +10,7 @@ class BirbnetesIoTPlatformPlaybackDriver:
@classmethod
def play_audio(cls, audiofile: str):
playsound(audiofile)
@classmethod
def cleanup(cls):
pass

View File

@ -4,6 +4,7 @@ import tempfile
from queue import Queue, Empty
from threading import Thread
import wave
import os
SAMPLE_RATE = 44100
MICROPHONE = 'default'
@ -11,7 +12,6 @@ DEST_FOLDER = "/dev/shm/"
class SlicedRecorder(Thread):
BYTES_PER_SAMPLE = 2 # 16bit
def __init__(self, slice_size: float, sample_rate=SAMPLE_RATE, microphone=MICROPHONE, dest_folder=DEST_FOLDER):
@ -78,11 +78,24 @@ class SlicedRecorder(Thread):
class BirbnetesIoTPlatformRecordDriver:
sliced_recorder = None
@classmethod
def init(cls, sample_length_sec: float):
pass
def init(cls, sample_length_sec: float, sample_rate=SAMPLE_RATE, microphone=MICROPHONE, dest_folder=DEST_FOLDER):
cls.sliced_recorder = SlicedRecorder(sample_length_sec, sample_rate, microphone, dest_folder)
cls.sliced_recorder.start()
@classmethod
def get_recording(cls, blocking: bool = False):
pass
def get_recording(cls, blocking: bool = False) -> Optional[str]:
return cls.sliced_recorder.get_recording(blocking)
@classmethod
def cleanup(cls):
cls.sliced_recorder.stop()
while True:
fname = cls.sliced_recorder.get_recording(False)
if fname:
os.unlink(fname)
else:
break