-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.py
68 lines (49 loc) · 1.79 KB
/
main.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
from pynput.keyboard import Listener, Key, KeyCode
import sounddevice as sd
import soundfile as sf
import threading
# import platform as plt
from util import find_speaker_device
bruh_filename = "bruh.mp3"
boom_filename = "vine-boom.mp3"
huh_filename = "huh.mp3"
filenames = [bruh_filename, boom_filename, huh_filename]
sound_data = {}
for filename in filenames:
data, fs = sf.read(filename, dtype="float32")
sound_data[filename] = {"data": data, "fs": fs}
speaker_device_id = find_speaker_device()
def onPress(key: Key | KeyCode | None):
if isinstance(key, Key):
# huh
if (key == Key.alt_r) or (key.value.vk == 61):
huh_data = sound_data[huh_filename]["data"]
huh_fs = sound_data[huh_filename]["fs"]
def play():
sd.play(huh_data, huh_fs, device=speaker_device_id)
# sd.wait()
thread = threading.Thread(target=play)
thread.start()
# bruh sound effect
elif key == Key.cmd_r or key == Key.alt_gr:
bruh_data = sound_data[bruh_filename]["data"]
bruh_fs = sound_data[bruh_filename]["fs"]
def play():
sd.play(bruh_data, bruh_fs, device=speaker_device_id)
thread = threading.Thread(target=play)
thread.start()
# sd.wait()
# vine boom sound effect
elif key == Key.shift_r:
boom_data = sound_data[boom_filename]["data"]
boom_fs = sound_data[boom_filename]["fs"]
def play():
sd.play(boom_data, boom_fs, device=speaker_device_id)
thread = threading.Thread(target=play)
thread.start()
# sd.wait()
def main():
listener = Listener(on_press=onPress)
listener.start()
listener.join()
main()