#!/usr/bin/env python3
"""Generate simple test audio WAV file using only stdlib"""

import wave
import struct
import math

# WAV parameters
sample_rate = 16000
duration = 2  # seconds
frequency = 440  # Hz (A4 note)

# Generate sine wave samples
samples = []
for i in range(int(sample_rate * duration)):
    # Sine wave value (-1.0 to 1.0)
    value = math.sin(2.0 * math.pi * frequency * i / sample_rate)

    # Convert to 16-bit PCM (-32768 to 32767)
    sample = int(value * 32767)
    samples.append(sample)

# Write WAV file
with wave.open("test_audio.wav", "w") as wav_file:
    # Set parameters (1 channel, 2 bytes per sample, 16kHz)
    wav_file.setnchannels(1)
    wav_file.setsampwidth(2)
    wav_file.setframerate(sample_rate)

    # Write frames
    for sample in samples:
        wav_file.writeframes(struct.pack('<h', sample))

print(f"[OK] Generated test_audio.wav")
print(f"  - Format: 16kHz, mono, 16-bit PCM")
print(f"  - Duration: {duration}s")
print(f"  - Frequency: {frequency}Hz (A4 tone)")
print(f"  - Samples: {len(samples)}")
