diff options
| author | HiFiPhile <[email protected]> | 2024-04-28 11:14:08 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-04-28 11:14:08 +0200 |
| commit | ee008620d2bd55ef3add37d372205cdde43d0e17 (patch) | |
| tree | 85b2ef0ad86106da7f3f0b5335c5a83eadb4bc20 /examples/device/audio_test_freertos/src/plot_audio_samples.py | |
| parent | 31b559370d29f5093979fc50de2ae415fa6612ce (diff) | |
| parent | ef7be4c2ffa0061aec2ea32f530a4037f7309f1e (diff) | |
Merge pull request #1709 from kaspernyhus/audio_test_freertos
Add audio_test_freertos & audio_4_channel_mic_freertos
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.py | 33 |
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() |
