Changed audio player to simpleaudio

This commit is contained in:
Pünkösd Marcell 2020-10-01 17:58:17 +02:00
parent 72576d1732
commit 5682590ced
4 changed files with 26 additions and 9 deletions

View File

@ -1,3 +1,3 @@
from .led_stuff import BirbnetesIoTPlatformStatusDriver, BlinkenLights from .led_stuff import BirbnetesIoTPlatformStatusDriver, BlinkenLights
from .playback_stuff import BirbnetesIoTPlatformPlaybackDriver from .playback_stuff import BirbnetesIoTPlatformPlaybackDriver, ShuffledFolderPlayer
from .record_stuff import BirbnetesIoTPlatformRecordDriver, SlicedRecorder from .record_stuff import BirbnetesIoTPlatformRecordDriver, SlicedRecorder

View File

@ -1,16 +1,33 @@
from playsound import playsound 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: class BirbnetesIoTPlatformPlaybackDriver:
shuffled_folder_player = None
@classmethod @classmethod
def init(cls): def init(cls, folder: str = '/var/lib/birbnetes/enemy_soudns'):
pass cls.shuffled_folder_player = ShuffledFolderPlayer(folder)
@classmethod @classmethod
def play_audio(cls, audiofile: str): def play_one_random(cls):
playsound(audiofile) cls.shuffled_folder_player.play_one_random()
@classmethod @classmethod
def cleanup(cls): def cleanup(cls):
pass simpleaudio.stop_all()

View File

@ -1,3 +1,3 @@
RPi.GPIO RPi.GPIO
pyalsaaudio pyalsaaudio
playsound simpleaudio

View File

@ -7,7 +7,7 @@ from setuptools import setup, find_packages
with open('README.md') as readme_file: with open('README.md') as readme_file:
readme = readme_file.read() readme = readme_file.read()
requirements = ['RPi.GPIO', 'pyalsaaudio', 'playsound'] requirements = ['RPi.GPIO', 'pyalsaaudio', 'simpleaudio']
setup_requirements = ['pytest-runner', ] setup_requirements = ['pytest-runner', ]