diff options
| author | HiFiPhile <[email protected]> | 2024-04-26 13:12:56 +0200 |
|---|---|---|
| committer | HiFiPhile <[email protected]> | 2024-04-26 13:12:56 +0200 |
| commit | 9ef3755f0316d25864d3ac3a49a2523eabfddf8a (patch) | |
| tree | 4fb337482662308674101d5269192b7a4fe58f91 /examples/device/audio_test_multi_rate/src/plot_audio_samples.py | |
| parent | f88a5bb03b2504df272d2cd285b17e66f11dfc64 (diff) | |
| parent | 69313ef45564cc8967575f47fb8c57371cbea470 (diff) | |
Merge branch 'master' of https://github.com/hathach/tinyusb into pr/2283
Diffstat (limited to 'examples/device/audio_test_multi_rate/src/plot_audio_samples.py')
| -rw-r--r-- | examples/device/audio_test_multi_rate/src/plot_audio_samples.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/examples/device/audio_test_multi_rate/src/plot_audio_samples.py b/examples/device/audio_test_multi_rate/src/plot_audio_samples.py new file mode 100644 index 000000000..c92e49957 --- /dev/null +++ b/examples/device/audio_test_multi_rate/src/plot_audio_samples.py @@ -0,0 +1,37 @@ +import sounddevice as sd +import matplotlib.pyplot as plt +import numpy as np +import platform +import csv + +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 = 96000 # Sample rate + duration = 100e-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() + + samples = np.array(myrecording) + np.savetxt('Output.csv', samples, delimiter=",", fmt='%s') |
