Jakob 9 months ago
commit
3a3ccb13c8

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
1
+*.wav

+ 72
- 0
campatmo.py View File

@@ -0,0 +1,72 @@
1
+#!/usr/bin/env python3
2
+import time
3
+import sys
4
+import random
5
+from glob import glob
6
+from pygame import mixer
7
+
8
+
9
+tracks_per_type = 2
10
+single_track_types = ["lines"]
11
+
12
+
13
+def load_files():
14
+    files = glob("samples/*.wav")
15
+    type_names = glob("samples/*/")
16
+    type_files = {c.split("/")[1]: glob(c + "/*.wav") for c in type_names}
17
+    return type_files
18
+
19
+
20
+def main():
21
+    type_files = load_files()
22
+    mixer.init(frequency=22050 * 2)
23
+    types = {}
24
+    i = 0
25
+    mixer.set_num_channels(
26
+        sum(
27
+            [
28
+                1 if name in single_track_types else tracks_per_type
29
+                for name in type_files
30
+            ]
31
+        )
32
+    )
33
+    print(f"{mixer.get_num_channels()} channels set")
34
+    for name in type_files:
35
+        types[name] = []
36
+        for k in range(1 if name in single_track_types else tracks_per_type):
37
+            types[name].append(mixer.Channel(i))
38
+            i += 1
39
+    sounds = {}
40
+    for name, files in type_files.items():
41
+        sounds[name] = []
42
+        for f in files:
43
+            sounds[name].append(mixer.Sound(f))
44
+        random.shuffle(sounds[name])
45
+    try:
46
+        while True:
47
+            for name, type_ in types.items():
48
+                if len(sounds[name]) == 0:
49
+                    continue
50
+                try:
51
+                    next_sound_index = max(
52
+                        [sounds[name].index(tt.get_queue() or tt.get_sound()) for tt in type_]
53
+                    )
54
+                except ValueError:
55
+                    next_sound_index = 0
56
+                if next_sound_index >= len(sounds[name]):
57
+                    random.shuffle(sounds[name])
58
+                    next_sound_index = 0
59
+                for c in type_:
60
+                    if c.get_queue() is not None and len(sounds[name]) > 1:
61
+                        continue
62
+                    c.queue(sounds[name][next_sound_index])
63
+                    if c.get_queue() is None and len(sounds[name]) > 1:
64
+                        c.queue(sounds[name][next_sound_index + 1])
65
+            time.sleep(1)
66
+    except KeyboardInterrupt:
67
+        print("exit")
68
+        sys.exit(0)
69
+
70
+
71
+if __name__ == "__main__":
72
+    main()

+ 0
- 0
samples/background/.exists View File


BIN
samples/background/1.mp3 View File


BIN
samples/background/1.wav View File


BIN
samples/background/2.mp3 View File


BIN
samples/background/2.wav View File


+ 0
- 0
samples/buzzwords/.exists View File


+ 0
- 0
samples/laughter/.exists View File


+ 0
- 0
samples/lines/.exists View File


+ 0
- 0
samples/other/.exists View File


Loading…
Cancel
Save