mirror of
https://github.com/cjfranko/NTP-Timeturner.git
synced 2025-11-08 10:22:02 +00:00
creates png of audio input
This commit is contained in:
parent
81e8313f45
commit
648aa221b1
1 changed files with 8 additions and 4 deletions
|
|
@ -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'")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue