diff options
| author | hathach <[email protected]> | 2025-02-12 11:28:16 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2025-02-12 11:28:16 +0700 |
| commit | 87adc63226a59e6c2602b1bc453ced77d44fedba (patch) | |
| tree | 1e47a80bfab09dbac47312b4242939df03ec7796 /examples/device/audio_test_freertos/src/plot_audio_samples.py | |
| parent | b41f5eadb3143d0bfaf211d9bc84c95e5d623c29 (diff) | |
| parent | 5afcfb7522c4fd8b50512cfb277d8a3ccdbc5453 (diff) | |
Merge branch 'master' into fork/atoktoto/midihost
# Conflicts:
# hw/bsp/rp2040/family.cmake
# src/class/midi/midi.h
# src/class/midi/midi_device.c
# src/device/usbd_control.c
# src/host/hcd.h
# src/host/usbh.c
# src/host/usbh.h
Diffstat (limited to 'examples/device/audio_test_freertos/src/plot_audio_samples.py')
| -rwxr-xr-x | examples/device/audio_test_freertos/src/plot_audio_samples.py | 34 |
1 files changed, 34 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 100755 index 000000000..46738eb3f --- /dev/null +++ b/examples/device/audio_test_freertos/src/plot_audio_samples.py @@ -0,0 +1,34 @@ +#!/usr/bin/env python3 +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() |
