added wav_recorder.py
parent
2415377e44
commit
575754a294
Binary file not shown.
|
|
@ -0,0 +1,29 @@
|
||||||
|
import wave
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
FIFO_PATH = "/tmp/esp32_audio"
|
||||||
|
OUTPUT_FILE = "recorded_audio.wav"
|
||||||
|
|
||||||
|
SAMPLE_RATE = 16000
|
||||||
|
CHANNELS = 2 # stereo from ESP32
|
||||||
|
BYTES_PER_SAMPLE = 2
|
||||||
|
|
||||||
|
# configure WAV writer
|
||||||
|
out_wav = wave.open(OUTPUT_FILE, "wb")
|
||||||
|
out_wav.setnchannels(CHANNELS)
|
||||||
|
out_wav.setsampwidth(BYTES_PER_SAMPLE)
|
||||||
|
out_wav.setframerate(SAMPLE_RATE)
|
||||||
|
|
||||||
|
with open(FIFO_PATH, "rb") as f:
|
||||||
|
print(f"Recording from {FIFO_PATH} into {OUTPUT_FILE}...")
|
||||||
|
try:
|
||||||
|
while True:
|
||||||
|
data = f.read(8000) # ~0.125s stereo
|
||||||
|
if not data:
|
||||||
|
continue
|
||||||
|
out_wav.writeframes(data)
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("\nStopping recording.")
|
||||||
|
finally:
|
||||||
|
out_wav.close()
|
||||||
|
print(f"Saved {OUTPUT_FILE}")
|
||||||
Loading…
Reference in New Issue