summaryrefslogtreecommitdiff
path: root/examples/device/audio_test_freertos/src/plot_audio_samples.py
diff options
context:
space:
mode:
authorHiFiPhile <[email protected]>2024-05-08 23:18:29 +0200
committerHiFiPhile <[email protected]>2024-05-08 23:18:29 +0200
commit8133af4e08394ac4940e7cee7a98c28d39bdb297 (patch)
tree4725620955a46c2ebc3dc719a06412ff6c574291 /examples/device/audio_test_freertos/src/plot_audio_samples.py
parent0e907b49c90d53023731dd1e21bbdcb1fdb95e11 (diff)
parent74e57499baac36c4cccf76549259905162031e41 (diff)
Merge remote-tracking branch 'remotes/tinyusb/master' into rx_fb
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()