File size: 1,768 Bytes
b924c47
 
e7c1a47
b924c47
 
e7c1a47
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b924c47
e7c1a47
b924c47
 
 
 
 
e7c1a47
 
 
 
 
b924c47
 
 
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
import gradio as gr
import numpy as np
from scipy.io.wavfile import write
import tempfile

def simulate_amber_alert_vibration(file):
    # Sampling parameters
    sample_rate = 44100  # Standard audio sample rate (44.1 kHz)
    burst_frequency = 50  # Low frequency (50 Hz) for vibration-like sound
    burst_duration = 0.5  # Duration of each burst in seconds
    silence_duration = 0.5  # Silence between bursts in seconds
    num_bursts = 5  # Number of vibration bursts

    # Generate a single burst of low-frequency sound
    t_burst = np.linspace(0, burst_duration, int(sample_rate * burst_duration), endpoint=False)
    burst_wave = 0.5 * np.sin(2 * np.pi * burst_frequency * t_burst)  # 50 Hz sine wave

    # Generate silence
    t_silence = np.linspace(0, silence_duration, int(sample_rate * silence_duration), endpoint=False)
    silence_wave = np.zeros_like(t_silence)

    # Combine bursts and silence to simulate vibration pattern
    vibration_wave = np.concatenate([np.concatenate([burst_wave, silence_wave]) for _ in range(num_bursts)])

    # Normalize to 16-bit PCM format
    vibration_wave = (vibration_wave * 32767).astype(np.int16)

    # Save to a temporary WAV file
    temp_file = tempfile.NamedTemporaryFile(delete=False, suffix=".wav")
    write(temp_file.name, sample_rate, vibration_wave)

    return temp_file.name

# Gradio Interface
interface = gr.Interface(
    fn=simulate_amber_alert_vibration,
    inputs=gr.Audio(label="Upload a WAV file (optional)", type="filepath"),
    outputs=gr.Audio(label="Simulated Amber Alert Vibration"),
    title="Amber Alert Vibration Simulation",
    description="Simulate an Amber Alert-style vibration using low-frequency audio. Play the generated audio to feel the effect."
)

interface.launch()