-
Notifications
You must be signed in to change notification settings - Fork 0
/
sound.py
29 lines (25 loc) · 892 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
from pygame import mixer
import logger as l
import pathlib
import os
wrong_loc = fr"{pathlib.Path.cwd()}\assets\wrong.wav"
correct_loc = fr"{pathlib.Path.cwd()}\assets\correct.wav"
def init():
global wrong_loc, correct_loc
l.log(type="DEBUG",message="Initializing mixer, please wait")
mixer.init()
if os.path.isfile(wrong_loc) == False:
wrong_loc = fr"{pathlib.Path.cwd()}\_internal\assets\wrong.wav"
correct_loc = fr"{pathlib.Path.cwd()}\_internal\assets\correct.wav"
def wrong():
global wrong_loc
try:
mixer.Channel(2).play(mixer.Sound(wrong_loc))
except Exception as e:
l.log(type="ERROR",message=f"Failed to play sound. {e}")
def correct():
global correct_loc
try:
mixer.Channel(1).play(mixer.Sound(correct_loc))
except Exception as e:
l.log(type="ERROR",message=f"Failed to play sound. {e}")