mirror of
https://git.exozy.me/a/Never-Gonna-Give-Beep-Up
synced 2024-11-22 11:47:29 +00:00
Use pysinewave (terrible library :(((()))))
This commit is contained in:
parent
62ceacf109
commit
ef083f3740
30
beepemu
Executable file
30
beepemu
Executable file
@ -0,0 +1,30 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
import math
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
from pysinewave import SineWave
|
||||||
|
|
||||||
|
i = 1
|
||||||
|
f = 0
|
||||||
|
l = 0
|
||||||
|
while i < len(sys.argv):
|
||||||
|
if sys.argv[i] == '-f':
|
||||||
|
i += 1
|
||||||
|
f = float(sys.argv[i])
|
||||||
|
elif sys.argv[i] == '-l':
|
||||||
|
i += 1
|
||||||
|
l = float(sys.argv[i])/1000
|
||||||
|
elif sys.argv[i] == '-D':
|
||||||
|
i += 1
|
||||||
|
time.sleep(float(sys.argv[i])/1000)
|
||||||
|
if f != 0 and l != 0:
|
||||||
|
print(f, l)
|
||||||
|
s = SineWave(pitch_per_second=1000)
|
||||||
|
s.set_frequency(f)
|
||||||
|
s.play()
|
||||||
|
time.sleep(l)
|
||||||
|
s.stop()
|
||||||
|
f = 0
|
||||||
|
l = 0
|
||||||
|
i += 1
|
14
mic.py
14
mic.py
@ -6,7 +6,7 @@ audio = pyaudio.PyAudio()
|
|||||||
stream = audio.open(
|
stream = audio.open(
|
||||||
format = pyaudio.paInt16,
|
format = pyaudio.paInt16,
|
||||||
channels = 1,
|
channels = 1,
|
||||||
rate=44100,
|
rate=88200,
|
||||||
input=True
|
input=True
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -16,21 +16,21 @@ curfreq = 0
|
|||||||
stop = False
|
stop = False
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
chunk = stream.read(2048)
|
chunk = stream.read(4096)
|
||||||
w = np.fft.fft(list(chunk))[10:100]
|
w = np.fft.fft(list(chunk))[10:200]
|
||||||
f = np.fft.fftfreq(4196)
|
f = np.fft.fftfreq(8192)
|
||||||
i = 10+np.argmax(np.abs(w))
|
i = 10+np.argmax(np.abs(w))
|
||||||
mag = abs(w[i-10])
|
mag = abs(w[i-10])
|
||||||
freq = abs(2 * f[i] * 44100)
|
freq = abs(2 * f[i] * 88200)
|
||||||
|
|
||||||
if mag > 50000 and curfreq == 0:
|
if mag > 100000 and curfreq == 0:
|
||||||
# Detected mic input
|
# Detected mic input
|
||||||
# Start new freq
|
# Start new freq
|
||||||
stop = False
|
stop = False
|
||||||
curfreq = freq
|
curfreq = freq
|
||||||
print('Starting', curfreq)
|
print('Starting', curfreq)
|
||||||
get('http://10.242.6.228:5000/startfreq/' + str(curfreq))
|
get('http://10.242.6.228:5000/startfreq/' + str(curfreq))
|
||||||
elif mag <= 50000 or abs(curfreq-freq) > 20:
|
elif mag <= 100000 or abs(curfreq-freq) > 20:
|
||||||
if stop and curfreq != 0:
|
if stop and curfreq != 0:
|
||||||
print('Stopping', curfreq)
|
print('Stopping', curfreq)
|
||||||
get('http://10.242.6.228:5000/stopfreq/' + str(curfreq))
|
get('http://10.242.6.228:5000/stopfreq/' + str(curfreq))
|
||||||
|
Loading…
Reference in New Issue
Block a user