34 lines
818 B
Python
34 lines
818 B
Python
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()
|
|
|
|
|
|
class BirbnetesIoTPlatformPlaybackDriver:
|
|
shuffled_folder_player = None
|
|
|
|
@classmethod
|
|
def init(cls, folder: str = '/var/lib/birbnetes/enemy_soudns'):
|
|
cls.shuffled_folder_player = ShuffledFolderPlayer(folder)
|
|
|
|
@classmethod
|
|
def play_one_random(cls):
|
|
cls.shuffled_folder_player.play_one_random()
|
|
|
|
@classmethod
|
|
def cleanup(cls):
|
|
simpleaudio.stop_all()
|