summaryrefslogtreecommitdiff
path: root/examples/device/audio_4_channel_mic/src/plot_audio_samples.py
blob: 0bd6f3b5d69a63331e6743c0827de7f7aa0b6b99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import sounddevice as sd
import matplotlib.pyplot as plt
import numpy as np

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)

    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)

    myrecording = sd.rec(int(duration * fs), samplerate=fs, channels=4, 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 4 Channel')
    plt.show()