2020-10-01 17:58:17 +02:00
|
|
|
import simpleaudio
|
|
|
|
import random
|
|
|
|
import os
|
|
|
|
import os.path
|
|
|
|
|
|
|
|
|
|
|
|
class ShuffledFolderPlayer:
|
|
|
|
|
|
|
|
def __init__(self, folder: str):
|
|
|
|
self._sounds = []
|
|
|
|
for folder_element in os.listdir(folder):
|
|
|
|
self._sounds.append(
|
|
|
|
simpleaudio.WaveObject.from_wave_file(os.path.join(folder, folder_element))
|
|
|
|
)
|
|
|
|
|
|
|
|
def play_one_random(self):
|
|
|
|
random.choice(self._sounds).play()
|
2020-09-30 00:15:17 +02:00
|
|
|
|
|
|
|
|
|
|
|
class BirbnetesIoTPlatformPlaybackDriver:
|
2020-10-01 17:58:17 +02:00
|
|
|
shuffled_folder_player = None
|
2020-09-30 00:15:17 +02:00
|
|
|
|
|
|
|
@classmethod
|
2020-10-01 17:58:17 +02:00
|
|
|
def init(cls, folder: str = '/var/lib/birbnetes/enemy_soudns'):
|
|
|
|
cls.shuffled_folder_player = ShuffledFolderPlayer(folder)
|
2020-09-30 00:15:17 +02:00
|
|
|
|
|
|
|
@classmethod
|
2020-10-01 17:58:17 +02:00
|
|
|
def play_one_random(cls):
|
|
|
|
cls.shuffled_folder_player.play_one_random()
|
2020-09-30 03:12:25 +02:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def cleanup(cls):
|
2020-10-01 17:58:17 +02:00
|
|
|
simpleaudio.stop_all()
|