summaryrefslogtreecommitdiff
path: root/examples/device/audio_test_freertos/src/plot_audio_samples.py
diff options
context:
space:
mode:
authorHiFiPhile <[email protected]>2024-05-07 12:32:28 +0200
committerGitHub <[email protected]>2024-05-07 12:32:28 +0200
commit4abdfc10f5a4cca19a614133655c64fec5752eb0 (patch)
treef79aa084a42438667b5e26b588a6f794c9ad1608 /examples/device/audio_test_freertos/src/plot_audio_samples.py
parent798ff807b3361a5859945cb23c3d0fd7d1a5679f (diff)
parente5b6f93df35d7ac413ca405e67a6c9d8c79b680d (diff)
Merge branch 'master' into remove-tud_network_link_state_cb
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()