summaryrefslogtreecommitdiff
path: root/examples/device/audio_test/src/plot_audio_samples.py
diff options
context:
space:
mode:
authorReinhard Panhuber <[email protected]>2021-03-13 11:37:38 +0100
committerReinhard Panhuber <[email protected]>2021-03-13 11:37:38 +0100
commitde3c03af76ebb4f092f798a390a463fe78cc27f0 (patch)
tree630e4875614a0d9991db373442f422221719bb6b /examples/device/audio_test/src/plot_audio_samples.py
parentdb6242f07615f85d8bd1bcf9b6e86c4e031ecc19 (diff)
Add python script to plot audio sample data.
Diffstat (limited to 'examples/device/audio_test/src/plot_audio_samples.py')
-rw-r--r--examples/device/audio_test/src/plot_audio_samples.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/examples/device/audio_test/src/plot_audio_samples.py b/examples/device/audio_test/src/plot_audio_samples.py
new file mode 100644
index 000000000..e6a9e2eec
--- /dev/null
+++ b/examples/device/audio_test/src/plot_audio_samples.py
@@ -0,0 +1,24 @@
+import sounddevice as sd
+import matplotlib.pyplot as plt
+import numpy as np
+
+if __name__ == '__main__':
+
+ # devList = sd.query_devices()
+ # print(devList)
+
+ fs = 48000 # Sample rate
+ duration = 100e-3 # Duration of recording
+ device = 'Microphone (MicNode) MME' # MME is needed since there are more than one MicNode device APIs (at least in Windows)
+
+ 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() \ No newline at end of file