|
|
Line 6: |
Line 6: |
|
| |
|
| <syntaxhighlight lang="python"> | | <syntaxhighlight lang="python"> |
|
| |
| import pyaudio
| |
| #import wave
| |
| import multiprocessing
| |
| import numpy as np
| |
| #import pickle #Not good for np arrays
| |
| import time
| |
| from pathlib import Path
| |
|
| |
| audio = pyaudio.PyAudio() # create pyaudio instantiation
| |
|
| |
| info = audio.get_host_api_info_by_index(0)
| |
| numdevices = info.get('deviceCount')
| |
| for i in range(0, numdevices):
| |
| if (audio.get_device_info_by_host_api_device_index(0, i).get('maxInputChannels')) > 0:
| |
| print( "Input Device id ", i, " - ", audio.get_device_info_by_host_api_device_index(0, i).get('name') )
| |
|
| |
|
| |
| form_1 = pyaudio.paInt16 # 16-bit resolution
| |
| chans = 1 # 1 channel
| |
| samp_rate = 44100 # 44.1kHz sampling rate
| |
| chunk = 4096 # 2^12 samples for buffer
| |
| record_secs = 10 # seconds to record
| |
| dev_index = 2 # device index found by p.get_device_info_by_index(ii)
| |
| wav_output_filename = 'test1.wav' # name of .wav file
| |
|
| |
|
| |
| print("recording")
| |
| frames = []
| |
|
| |
|
| </syntaxhighlight> | | </syntaxhighlight> |
Latest revision as of 09:53, 16 February 2021
Introduction
Use USB microphone to listen sound and FFT it to waveforms.
Theory