plot_audio_samples.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. import sounddevice as sd
  2. import matplotlib.pyplot as plt
  3. import numpy as np
  4. import platform
  5. if __name__ == '__main__':
  6. # If you got "ValueError: No input device matching", that is because your PC name example device
  7. # differently from tested list below. Uncomment the next line to see full list and try to pick correct one
  8. # print(sd.query_devices())
  9. fs = 48000 # Sample rate
  10. duration = 100e-3 # Duration of recording
  11. if platform.system() == 'Windows':
  12. # WDM-KS is needed since there are more than one MicNode device APIs (at least in Windows)
  13. device = 'Microphone (MicNode_4_Ch), Windows WDM-KS'
  14. elif platform.system() == 'Darwin':
  15. device = 'MicNode_4_Ch'
  16. else:
  17. device ='default'
  18. myrecording = sd.rec(int(duration * fs), samplerate=fs, channels=4, dtype='int16', device=device)
  19. print('Waiting...')
  20. sd.wait() # Wait until recording is finished
  21. print('Done!')
  22. time = np.arange(0, duration, 1 / fs) # time vector
  23. plt.plot(time, myrecording)
  24. plt.xlabel('Time [s]')
  25. plt.ylabel('Amplitude')
  26. plt.title('MicNode 4 Channel')
  27. plt.show()