aboutsummaryrefslogtreecommitdiff
path: root/Recv.py
diff options
context:
space:
mode:
Diffstat (limited to 'Recv.py')
-rw-r--r--Recv.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/Recv.py b/Recv.py
index e69de29..7da9f06 100644
--- a/Recv.py
+++ b/Recv.py
@@ -0,0 +1,47 @@
+import utils as u
+import time
+from collections import Counter
+
+def main():
+ p = u.pyaudio.PyAudio()
+ start_freq = 19800
+ freq_range = 200
+ bytes_per_transmit = 1
+
+ stream = p.open(
+ format=u.pyaudio.paInt32,
+ channels=1,
+ rate=44100,
+ input=True,
+ output=True,
+ frames_per_buffer=2048 * 2,
+ )
+
+ char_counter = Counter()
+ start_time = time.time()
+ word = ''
+
+ try:
+ while True:
+ current_time = time.time()
+ if current_time - start_time >= 1: # Every second
+ # Find the most common character
+ most_common_char, _ = char_counter.most_common(1)[0] if char_counter else ('', 0)
+ print(f"Most common character in the last second: {most_common_char}")
+ word += most_common_char
+ print(f"Accumulated word: {word}")
+ char_counter.clear() # Reset for the next second
+ start_time = current_time
+
+ data, success = u.receive_data(stream, start_freq, freq_range, bytes_per_transmit)
+ if success:
+ char_counter[data] += 1
+
+ except KeyboardInterrupt:
+ print("Stopping...")
+ finally:
+ stream.stop_stream()
+ stream.close()
+ p.terminate()
+if __name__ == "__main__":
+ main() \ No newline at end of file