blob: 7da9f066285635feed0b2e4d7b7547d4f4da1005 (
plain)
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
42
43
44
45
46
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()
|