-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdial.py
47 lines (36 loc) · 840 Bytes
/
dial.py
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
45
46
import array
import math
from threading import Event
from time import sleep
from signal import pause
import sys
import pyaudio
VOLUME = 0.3
SAMPLING_F = 44100
TONES = [350, 440]
CHUNK_SIZE = 40960
def main():
aud = pyaudio.PyAudio()
print("Running")
beat_width = 490
sample_length = beat_width * 9
samples = [
sum([
VOLUME * math.sin(2 * math.pi * tick * tone / SAMPLING_F)
for tone in TONES
])
for tick in range(sample_length)
]
print("Outputting sound")
bytes = array.array('f', samples).tobytes()
stream = aud.open(
format=pyaudio.paFloat32,
channels=1,
rate=SAMPLING_F,
frames_per_buffer=CHUNK_SIZE,
output=True,
)
while True:
stream.write(bytes)
if __name__ == "__main__":
main()