forked from v-s-v-i-s-h-w-a-s/ping-pong
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_sounds.py
More file actions
21 lines (17 loc) · 804 Bytes
/
create_sounds.py
File metadata and controls
21 lines (17 loc) · 804 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import numpy as np
from scipy.io import wavfile
def create_beep(freq, duration, amplitude=0.5, sample_rate=44100):
t = np.linspace(0, duration, int(sample_rate * duration))
wave = amplitude * np.sin(2 * np.pi * freq * t)
return (wave * 32767).astype(np.int16)
# Create paddle hit sound (higher pitch)
paddle_sound = create_beep(1000, 0.1)
wavfile.write('sounds/paddle_hit.wav', 44100, paddle_sound)
# Create wall hit sound (lower pitch)
wall_sound = create_beep(500, 0.1)
wavfile.write('sounds/wall_hit.wav', 44100, wall_sound)
# Create score sound (ascending tones)
score_duration = 0.2
t = np.linspace(0, score_duration, int(44100 * score_duration))
score_sound = create_beep(800, score_duration) + create_beep(1000, score_duration)
wavfile.write('sounds/score.wav', 44100, score_sound)