1import sounddevice as sd
2from scipy.io.wavfile import write
3
4fs = 44100 # Sample rate
5seconds = 3 # Duration of recording
6
7myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=2)
8sd.wait() # Wait until recording is finished
9write('output.wav', fs, myrecording) # Save as WAV file
10