summaryrefslogtreecommitdiff
path: root/examples/device/audio_test_freertos/src/plot_audio_samples.py
diff options
context:
space:
mode:
authorHiFiPhile <[email protected]>2024-08-02 11:52:35 +0200
committerGitHub <[email protected]>2024-08-02 11:52:35 +0200
commit95cb319bded7db536edaae24936a825a8524a4a2 (patch)
tree7de7d7f8d1916061cdaefcfb4f220397e1d0fbb8 /examples/device/audio_test_freertos/src/plot_audio_samples.py
parentadc7a78fd6fbdccbe5f586391997052f2becd149 (diff)
parent4232642899362fa5e9cf0dc59bad6f1f6d32c563 (diff)
Merge branch 'master' into vendor_fifo
Diffstat (limited to 'examples/device/audio_test_freertos/src/plot_audio_samples.py')
-rw-r--r--examples/device/audio_test_freertos/src/plot_audio_samples.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/examples/device/audio_test_freertos/src/plot_audio_samples.py b/examples/device/audio_test_freertos/src/plot_audio_samples.py
new file mode 100644
index 000000000..304b2d5de
--- /dev/null
+++ b/examples/device/audio_test_freertos/src/plot_audio_samples.py
@@ -0,0 +1,33 @@
+import sounddevice as sd
+import matplotlib.pyplot as plt
+import numpy as np
+import platform
+
+if __name__ == '__main__':
+
+ # If you got "ValueError: No input device matching", that is because your PC name example device
+ # differently from tested list below. Uncomment the next line to see full list and try to pick correct one
+ # print(sd.query_devices())
+
+ fs = 48000 # Sample rate
+ duration = 1000e-3 # Duration of recording
+
+ if platform.system() == 'Windows':
+ # MME is needed since there are more than one MicNode device APIs (at least in Windows)
+ device = 'Microphone (MicNode) MME'
+ elif platform.system() == 'Darwin':
+ device = 'MicNode'
+ else:
+ device ='default'
+
+ myrecording = sd.rec(int(duration * fs), samplerate=fs, channels=1, dtype='int16', device=device)
+ print('Waiting...')
+ sd.wait() # Wait until recording is finished
+ print('Done!')
+
+ time = np.arange(0, duration, 1 / fs) # time vector
+ plt.plot(time, myrecording)
+ plt.xlabel('Time [s]')
+ plt.ylabel('Amplitude')
+ plt.title('MicNode')
+ plt.show()