-
Notifications
You must be signed in to change notification settings - Fork 1
/
sounds.py
30 lines (27 loc) · 1.08 KB
/
sounds.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import subprocess
import os
class Sounds:
def __init__(self):
""" Constructor for Member variables """
self.playing = [] # List of dings and dongs
self.limit_number = 4
def Play(self, sound_file):
""" Play Dong Sound """
self.processPlaying(self.playing, self.limit_number)
filename = 'sounds/' + sound_file
if sound_file != "" and os.path.isfile(filename):
self.playing.append(
subprocess.Popen(["/usr/bin/aplay", '-q', filename])
)
return
def processPlaying(self, playing, limit_number):
""" Remove finished sound processes and
limit sound processes to a set number """
count = len(playing)
if (count >= limit_number):
# Remove the first few until process count is low enough
for n in range(0, (count-limit_number)):
item = playing[0]
if item.poll() is None:
item.terminate() # Wasnt finished, make it finished
playing.pop(0) # remove first item from list