-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvox.py
76 lines (62 loc) · 1.86 KB
/
vox.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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from pygame import mixer
import time
import os
from pyogg import VorbisFile
import random
def selectFile(old_state, new_state):
pass
sounds_folder = "sounds"
folder_path = sounds_folder + "/" + old_state + "2" + new_state
print(folder_path)
ra = random.choice(os.listdir(folder_path))
return folder_path + "/" + ra
def fadeout(tiem):
pass
mixer.music.fadeout(tiem)
def playPath(path):
print(path)
mixer.quit()
sound = VorbisFile(path)
frequency = sound.frequency
mixer.init(frequency=frequency)
mixer.music.load(path)
mixer.music.set_volume(1.0)
mixer.music.play()
# while mixer.music.get_busy() == True:
# pass
def play_audio_from_state(old_state, new_state):
try:
print("received states: " + old_state + ", " + new_state)
selected_sound = selectFile(old_state, new_state)
print(selected_sound)
playPath(selected_sound)
except:
print("failed to play audio")
if __name__ == "__main__":
# playPath("sounds/broken2building/prehub10.mp3")
# time.sleep(6)
# print(selectFile("broken", "good"))
# selected_sound = selectFile("broken", "xxx")
selected_sound = "../sounds/error.ogg"
playPath(selected_sound)
time.sleep(5)
fadeout(5000)
time.sleep(10)
# try:
# selected_sound = selectFile("building", "good")
# playPath(selected_sound)
# time.sleep(6)
# except:
# print("failed to play audio")
# play_audio_from_state("building", "good")
# time.sleep(10)
# states = ["building", "broken", "good"]
# old_state = random.choice(states)
# while True:
# state = random.choice(states)
# if old_state != state:
# play_audio_from_state(old_state, state)
# else:
# print("duplicate")
# old_state = state
# time.sleep(2)