creates png of audio input

This commit is contained in:
Chris Frankland-Wright 2025-06-24 20:12:37 +01:00
parent 81e8313f45
commit 648aa221b1

View file

@ -2,11 +2,13 @@
"""
test_audioinput.py
Quick sanity check to ensure audio input device is working.
Records 2 seconds of audio from default input and plots waveform.
Records 2 seconds of audio from the default input device
and saves the waveform as 'waveform.png' works headless.
"""
import numpy as np
import matplotlib
matplotlib.use('Agg') # Headless backend
import matplotlib.pyplot as plt
import sounddevice as sd
@ -21,7 +23,7 @@ sd.wait()
# Generate time axis
time_axis = np.linspace(0, DURATION, len(recording))
# Plot
# Plot and save
plt.figure(figsize=(10, 4))
plt.plot(time_axis, recording, linewidth=0.5)
plt.title("Audio Input Waveform")
@ -29,4 +31,6 @@ plt.xlabel("Time [s]")
plt.ylabel("Amplitude")
plt.grid(True)
plt.tight_layout()
plt.show()
plt.savefig("waveform.png")
print("✅ Waveform saved as 'waveform.png'")