forked from dheera/scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbeep
More file actions
executable file
·41 lines (36 loc) · 888 Bytes
/
beep
File metadata and controls
executable file
·41 lines (36 loc) · 888 Bytes
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
#!/usr/bin/env python3
import datetime
import json
import numpy
import os
import pyaudio
import subprocess
import sys
import threading
import time
if __name__ == "__main__":
f = 440
T = 0.15
A = 0.5
wave = 'sq'
if len(sys.argv) >= 2:
f = float(sys.argv[1])
if len(sys.argv) >= 3:
T = float(sys.argv[2])
if len(sys.argv) >= 4:
A = float(sys.argv[3])
if len(sys.argv) >= 5:
wave = sys.argv[4]
samples = numpy.arange(44100 * T) / 44100.0
if wave == 'sq':
wave = min(A, 1) * 127 * (numpy.mod(numpy.floor(samples * f * 2), 2) * 2 - 1)
elif wave == 'sin':
wave = min(A, 1) * 127 * (numpy.sin(2 * numpy.pi * f * samples))
pa = pyaudio.PyAudio()
stream = pa.open(format=pyaudio.paInt8,
channels=1,
rate=44100,
output=True)
stream.write(numpy.array(wave, dtype = numpy.int8))
stream.stop_stream()
stream.close()