Changed audio player to simpleaudio
This commit is contained in:
parent
72576d1732
commit
5682590ced
@ -1,3 +1,3 @@
|
||||
from .led_stuff import BirbnetesIoTPlatformStatusDriver, BlinkenLights
|
||||
from .playback_stuff import BirbnetesIoTPlatformPlaybackDriver
|
||||
from .playback_stuff import BirbnetesIoTPlatformPlaybackDriver, ShuffledFolderPlayer
|
||||
from .record_stuff import BirbnetesIoTPlatformRecordDriver, SlicedRecorder
|
||||
|
@ -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:
|
||||
shuffled_folder_player = None
|
||||
|
||||
@classmethod
|
||||
def init(cls):
|
||||
pass
|
||||
def init(cls, folder: str = '/var/lib/birbnetes/enemy_soudns'):
|
||||
cls.shuffled_folder_player = ShuffledFolderPlayer(folder)
|
||||
|
||||
@classmethod
|
||||
def play_audio(cls, audiofile: str):
|
||||
playsound(audiofile)
|
||||
def play_one_random(cls):
|
||||
cls.shuffled_folder_player.play_one_random()
|
||||
|
||||
@classmethod
|
||||
def cleanup(cls):
|
||||
pass
|
||||
simpleaudio.stop_all()
|
||||
|
@ -1,3 +1,3 @@
|
||||
RPi.GPIO
|
||||
pyalsaaudio
|
||||
playsound
|
||||
simpleaudio
|
2
setup.py
2
setup.py
@ -7,7 +7,7 @@ from setuptools import setup, find_packages
|
||||
with open('README.md') as readme_file:
|
||||
readme = readme_file.read()
|
||||
|
||||
requirements = ['RPi.GPIO', 'pyalsaaudio', 'playsound']
|
||||
requirements = ['RPi.GPIO', 'pyalsaaudio', 'simpleaudio']
|
||||
|
||||
setup_requirements = ['pytest-runner', ]
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user