aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnthony Wang2022-10-03 17:54:32 -0400
committerAnthony Wang2022-10-03 17:54:32 -0400
commitef083f3740516570e64112ed0aa6bb8220a88604 (patch)
treee9b380e238e7c1d4d35183a0dee96bc8ca063490
parent62ceacf10980ef96b1a227d76cdf3e7db82fd4de (diff)
Use pysinewave (terrible library :(((()))))
-rwxr-xr-xbeepemu30
-rw-r--r--mic.py14
2 files changed, 37 insertions, 7 deletions
diff --git a/beepemu b/beepemu
new file mode 100755
index 0000000..b74d197
--- /dev/null
+++ b/beepemu
@@ -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
diff --git a/mic.py b/mic.py
index 9b518f3..18b73e8 100644
--- a/mic.py
+++ b/mic.py
@@ -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))