1
0
mirror of https://git.exozy.me/a/Never-Gonna-Give-Beep-Up synced 2024-11-22 06:37:31 +00:00

Use pysinewave (terrible library :(((()))))

This commit is contained in:
Anthony Wang 2022-10-03 17:54:32 -04:00
parent 62ceacf109
commit ef083f3740
No known key found for this signature in database
GPG Key ID: 42A5B952E6DD8D38
2 changed files with 37 additions and 7 deletions

30
beepemu Executable file
View 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
View File

@ -6,7 +6,7 @@ audio = pyaudio.PyAudio()
stream = audio.open(
format = pyaudio.paInt16,
channels = 1,
rate=44100,
rate=88200,
input=True
)
@ -16,21 +16,21 @@ curfreq = 0
stop = False
while True:
chunk = stream.read(2048)
w = np.fft.fft(list(chunk))[10:100]
f = np.fft.fftfreq(4196)
chunk = stream.read(4096)
w = np.fft.fft(list(chunk))[10:200]
f = np.fft.fftfreq(8192)
i = 10+np.argmax(np.abs(w))
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
# Start new freq
stop = False
curfreq = freq
print('Starting', 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:
print('Stopping', curfreq)
get('http://10.242.6.228:5000/stopfreq/' + str(curfreq))