-
Notifications
You must be signed in to change notification settings - Fork 0
/
segnale_con_annuncio.py
63 lines (53 loc) · 1.92 KB
/
segnale_con_annuncio.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
import numpy as np
import sounddevice as sd
from gtts import gTTS
from playsound import playsound
from datetime import datetime
def generate_tone(frequency, duration_ms, sample_rate):
t = np.linspace(0, duration_ms / 1000.0, int(sample_rate * duration_ms / 1000.0), False)
return 0.5 * np.sin(2 * np.pi * frequency * t)
sample_rate = 44100
tone_duration_ms = 30
impulse_duration_ms = 100
frequencies = [2000, 2500]
impulse_frequency = 1000
segment_52_53 = np.concatenate([
np.concatenate([generate_tone(frequencies[0], tone_duration_ms, sample_rate),
generate_tone(frequencies[1], tone_duration_ms, sample_rate)])
for _ in range(16)
])
impulses = np.concatenate([
np.concatenate([generate_tone(impulse_frequency, impulse_duration_ms, sample_rate),
np.zeros(int(sample_rate * 0.9))])
for _ in range(5)
])
last_impulse = np.concatenate([np.zeros(int(sample_rate)), generate_tone(impulse_frequency, impulse_duration_ms, sample_rate)])
full_signal = np.concatenate([segment_52_53, np.zeros(int(sample_rate)), impulses, last_impulse, np.zeros(int(sample_rate))])
sd.play(full_signal, sample_rate)
sd.wait()
current_time = datetime.now()
hour = current_time.hour
minute = current_time.minute
if hour == 0:
if minute == 0:
time_message = "È mezzanotte"
elif minute == 1:
time_message = "È mezzanotte, e un minuto"
else:
time_message = f"È mezzanotte, e {minute} minuti"
elif hour == 1:
if minute == 0:
time_message = "È l'una?"
elif minute == 1:
time_message = "Ore una, e un minuto"
else:
time_message = f"Ore una, e {minute} minuti"
elif minute == 0:
time_message = f"Ore {hour}?"
elif minute == 1:
time_message = f"Ore {hour}, e un minuto"
else:
time_message = f"Ore {hour}, e {minute} minuti"
tts = gTTS(time_message, lang='it', slow=False)
tts.save("time_announcement.mp3")
playsound("time_announcement.mp3")