-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgenerate_alert_sound.py
More file actions
44 lines (35 loc) · 1.21 KB
/
generate_alert_sound.py
File metadata and controls
44 lines (35 loc) · 1.21 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
"""
Simple script to generate a beep sound for alert (without SciPy)
"""
import numpy as np
import wave
import os
# Audio parameters
sample_rate = 44100 # Hz
duration = 1.0 # seconds
frequency = 1000 # Hz (beep tone)
# Generate time array
t = np.linspace(0, duration, int(sample_rate * duration))
# Generate sine wave for beep
amplitude = 0.5
beep = amplitude * np.sin(2 * np.pi * frequency * t)
# Add envelope to prevent clicking
envelope = np.ones_like(t)
fade_samples = int(0.01 * sample_rate) # 10ms fade
envelope[:fade_samples] = np.linspace(0, 1, fade_samples)
envelope[-fade_samples:] = np.linspace(1, 0, fade_samples)
beep = beep * envelope
# Convert to 16-bit integer
beep_int = np.int16(beep * 32767)
# Create assets directory if it doesn't exist
assets_dir = os.path.join(os.path.dirname(__file__), 'frontend', 'assets')
os.makedirs(assets_dir, exist_ok=True)
# Save as WAV file
output_path = os.path.join(assets_dir, 'alert-sound.wav')
# Write WAV file
with wave.open(output_path, 'w') as wav_file:
wav_file.setnchannels(1) # Mono
wav_file.setsampwidth(2) # 16-bit
wav_file.setframerate(sample_rate)
wav_file.writeframes(beep_int.tobytes())
print(f"[OK] Alert sound generated: {output_path}")