diff options
| author | HiFiPhile <[email protected]> | 2024-10-30 19:36:05 +0100 |
|---|---|---|
| committer | HiFiPhile <[email protected]> | 2024-10-30 19:47:03 +0100 |
| commit | 85ff529a310b7e6ec2e4234e3e292fef6432882b (patch) | |
| tree | 41218fce4db7c23df1073dfdd42fb017c3cf0158 /examples/device/audio_test_freertos/src/plot_audio_samples.py | |
| parent | 418b8b2f133d695362c735f271c966af10b5d251 (diff) | |
| parent | 8b1e40c3e2447de5b4a86bbcdcc0344946a4793d (diff) | |
Merge branch 'master' into dcd_notif
Signed-off-by: HiFiPhile <[email protected]>
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() |
