| 1234567891011121314151617181920 |
- """Original short, softly enveloped cues; reproducible, no external audio license."""
- import math, struct, wave
- from pathlib import Path
- root = Path(__file__).resolve().parent.parent / 'public/assets/audio'
- root.mkdir(parents=True, exist_ok=True)
- for kind, notes in [('success', [(660, 0, .14), (880, .075, .16)]), ('error', [(330, 0, .17)])]:
- rate, duration = 22050, .26
- frames = []
- for i in range(int(rate * duration)):
- t = i / rate
- value = 0
- for freq, start, length in notes:
- x = t - start
- if 0 <= x < length:
- envelope = min(1, x / .012) * (1 - x / length) ** 2
- value += .32 * envelope * math.sin(2 * math.pi * freq * x)
- frames.append(struct.pack('<h', round(value * 32767)))
- with wave.open(str(root / f'learning-{kind}.wav'), 'wb') as output:
- output.setparams((1, 2, rate, 0, 'NONE', 'not compressed'))
- output.writeframes(b''.join(frames))
|