17 lines
432 B
Python
17 lines
432 B
Python
import numpy as np
|
|
import time
|
|
|
|
SAMPLERATE = 16000
|
|
CHANNELS = 1
|
|
BLOCKSIZE = 256
|
|
|
|
with open("/tmp/esp32_audio", "rb") as f:
|
|
while True:
|
|
data = f.read(BLOCKSIZE * CHANNELS * 2) # 2 bytes per sample
|
|
if not data:
|
|
continue
|
|
audio = np.frombuffer(data, dtype=np.int16)
|
|
peak = np.max(np.abs(audio))
|
|
bar = "#" * int(peak * 50 / 32767)
|
|
print(f"[{bar:<50}] {peak}", flush=True)
|