summaryrefslogtreecommitdiff
path: root/examples/device/audio_test_freertos/src/plot_audio_samples.py
diff options
context:
space:
mode:
authorHiFiPhile <[email protected]>2024-06-27 20:49:40 +0200
committerHiFiPhile <[email protected]>2024-06-27 20:49:40 +0200
commiteefca229b64bddf07ae862248f4a1071984a7fe1 (patch)
tree57e8686adc49dda0d19a8fc1b34e45548ec399ed /examples/device/audio_test_freertos/src/plot_audio_samples.py
parent02ec4866105eca3f95e7392e538caf97ebb902b4 (diff)
parent13dedddd1963e67251f75b3e3ebd654d74d8aa56 (diff)
Merge branch 'master' of https://github.com/hathach/tinyusb into dwc2_dma
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()