From de3c03af76ebb4f092f798a390a463fe78cc27f0 Mon Sep 17 00:00:00 2001 From: Reinhard Panhuber Date: Sat, 13 Mar 2021 11:37:38 +0100 Subject: Add python script to plot audio sample data. --- .../device/audio_test/src/plot_audio_samples.py | 24 ++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 examples/device/audio_test/src/plot_audio_samples.py (limited to 'examples/device/audio_test/src/plot_audio_samples.py') 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 -- cgit v1.3.1 From d566444d584f644afc580ff9d3cf8e1adc7ccb30 Mon Sep 17 00:00:00 2001 From: Reinhard Panhuber Date: Sat, 13 Mar 2021 11:41:46 +0100 Subject: Add new line at end of python script --- examples/device/audio_test/src/plot_audio_samples.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'examples/device/audio_test/src/plot_audio_samples.py') diff --git a/examples/device/audio_test/src/plot_audio_samples.py b/examples/device/audio_test/src/plot_audio_samples.py index e6a9e2eec..0b0c3394f 100644 --- a/examples/device/audio_test/src/plot_audio_samples.py +++ b/examples/device/audio_test/src/plot_audio_samples.py @@ -21,4 +21,5 @@ if __name__ == '__main__': plt.xlabel('Time [s]') plt.ylabel('Amplitude') plt.title('MicNode') - plt.show() \ No newline at end of file + plt.show() + \ No newline at end of file -- cgit v1.3.1 From ad11481dd16112a38ab05754bafb33599af38f9d Mon Sep 17 00:00:00 2001 From: hathach Date: Thu, 15 Apr 2021 12:08:50 +0700 Subject: update plot script to work on macos and linux also add note for installing pip module --- examples/device/audio_4_channel_mic/src/main.c | 8 ++++++++ .../audio_4_channel_mic/src/plot_audio_samples.py | 20 ++++++++++++++------ examples/device/audio_test/src/main.c | 8 ++++++++ examples/device/audio_test/src/plot_audio_samples.py | 19 ++++++++++++++----- 4 files changed, 44 insertions(+), 11 deletions(-) (limited to 'examples/device/audio_test/src/plot_audio_samples.py') diff --git a/examples/device/audio_4_channel_mic/src/main.c b/examples/device/audio_4_channel_mic/src/main.c index 6e1ea1e6a..99e850dcc 100644 --- a/examples/device/audio_4_channel_mic/src/main.c +++ b/examples/device/audio_4_channel_mic/src/main.c @@ -23,6 +23,14 @@ * */ +/* plot_audio_samples.py requires following modules: + * $ sudo apt install libportaudio + * $ pip3 install sounddevice matplotlib + * + * Then run + * $ python3 plot_audio_samples.py + */ + #include #include #include diff --git a/examples/device/audio_4_channel_mic/src/plot_audio_samples.py b/examples/device/audio_4_channel_mic/src/plot_audio_samples.py index 0bd6f3b5d..9ab15135d 100644 --- a/examples/device/audio_4_channel_mic/src/plot_audio_samples.py +++ b/examples/device/audio_4_channel_mic/src/plot_audio_samples.py @@ -1,16 +1,24 @@ import sounddevice as sd import matplotlib.pyplot as plt import numpy as np +import platform if __name__ == '__main__': - # Currently tested for Windows - on Linux try to find the device or use default device if not clearly listed - # devList = sd.query_devices() - # print(devList) + # 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 = 100e-3 # Duration of recording - device = 'Microphone (MicNode_4_Ch), Windows WDM-KS' # WDM-KS is needed since there are more than one MicNode device APIs (at least in Windows) + fs = 48000 # Sample rate + duration = 100e-3 # Duration of recording + + if platform.system() == 'Windows': + # WDM-KS is needed since there are more than one MicNode device APIs (at least in Windows) + device = 'Microphone (MicNode_4_Ch), Windows WDM-KS' + elif platform.system() == 'Darwin': + device = 'MicNode_4_Ch' + else: + device ='default' myrecording = sd.rec(int(duration * fs), samplerate=fs, channels=4, dtype='int16', device=device) print('Waiting...') diff --git a/examples/device/audio_test/src/main.c b/examples/device/audio_test/src/main.c index 4de515b3b..9a2fdd3a1 100644 --- a/examples/device/audio_test/src/main.c +++ b/examples/device/audio_test/src/main.c @@ -23,6 +23,14 @@ * */ +/* plot_audio_samples.py requires following modules: + * $ sudo apt install libportaudio + * $ pip3 install sounddevice matplotlib + * + * Then run + * $ python3 plot_audio_samples.py + */ + #include #include #include diff --git a/examples/device/audio_test/src/plot_audio_samples.py b/examples/device/audio_test/src/plot_audio_samples.py index 0b0c3394f..6e3c4978e 100644 --- a/examples/device/audio_test/src/plot_audio_samples.py +++ b/examples/device/audio_test/src/plot_audio_samples.py @@ -1,15 +1,24 @@ import sounddevice as sd import matplotlib.pyplot as plt import numpy as np +import platform if __name__ == '__main__': - # devList = sd.query_devices() - # print(devList) + # 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 = 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) + fs = 48000 # 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...') -- cgit v1.3.1