-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsound.py
More file actions
80 lines (60 loc) · 1.88 KB
/
sound.py
File metadata and controls
80 lines (60 loc) · 1.88 KB
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
77
78
79
80
import time
import numpy as np
import pyttsx3
import sounddevice as sd
import subprocess
class Sound:
def __init__(self):
pass
def beep(self, frequency: float, duration: float, volume: float = 0.5):
sample_rate = 44100
time_points = np.linspace(0, duration, int(sample_rate * duration), endpoint=False)
wave = volume * np.sin(2 * np.pi * frequency * time_points)
sd.play(wave)
sd.wait()
def say(self, text: str, use_mac_system=True):
if not use_mac_system:
engine = pyttsx3.init()
voices = engine.getProperty("voices")
engine.setProperty("voice", voices[22].id)
engine.say(text)
engine.runAndWait()
else:
subprocess.run(['say', text])
def play_error_sound(self):
self.beep(440, 0.15)
self.beep(535.25, 0.15)
self.beep(622.25, 0.15)
def play_setup_sound(self):
self.beep(440, 0.2)
self.beep(554.37, 0.2)
self.beep(659.25, 0.2)
def play_disconnect_sound(self):
self.beep(659.25, 0.2)
self.beep(554.37, 0.2)
self.beep(440, 0.2)
def play_connecting_progress_sound(self):
self.beep(329.63, 0.1)
self.beep(329.63, 0.1)
self.beep(329.63, 0.1)
def play_connected_sound(self):
self.beep(261.33, 0.1)
self.beep(522.66, 0.1)
def play_ping_sound(self):
self.beep(880, 0.1)
def play_ping2_sound(self):
self.beep(493.88, 0.1)
def play_generic_task_sound(self):
self.beep(261.33, 0.1)
if __name__ == "__main__":
snd = Sound()
# snd.play_setup_sound()
# snd.play_error_sound()
#
# for i in range(2):
# snd.play_ping_sound()
# snd.play_generic_task_sound()
#
# snd.play_connecting_progress_sound()
snd.say("Connecting...")
snd.say("Setting homing mask...")