-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsound.py
44 lines (33 loc) · 888 Bytes
/
sound.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from time import sleep
import subprocess
sounds = {}
next_id = 0
def sound_finished(id):
return sounds[str(id)].poll() != None
def kill_all_sounds():
for sound in sounds.values():
sound.kill()
def _playsound_linux(file_source):
global next_id
sounds[str(next_id)] = subprocess.Popen(["aplay", file_source])
next_id+=1
return next_id-1
def _playsound_darwin(file_source):
global next_id
sounds[str(next_id)] = subprocess.Popen(["afplay", file_source])
next_id+=1
return next_id-1
def _playsound_win(file_source):
global next_id
sounds[str(next_id)] = subprocess.Popen(["python", "sound_win_slave.py", file_source])
next_id+=1
return next_id-1
from platform import system
system = system()
if system == 'Linux':
playsound = _playsound_linux
elif system == 'Windows':
playsound = _playsound_win
elif system == 'Darwin':
playsound = _playsound_darwin
del system