File size: 642 Bytes
191204a
 
 
 
 
3d9d61a
 
 
 
 
191204a
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import numpy as np
import sounddevice as sd
from scipy.io.wavfile import write


def run(fs=44100, seconds=3, out_filename="output.wav", ask_first=True):
    
    if ask_first:
        input("Press Enter to start recording:")
    
    print(f"Recording for {seconds}s...", end=" ")
    myrecording = sd.rec(int(seconds * fs), samplerate=fs, channels=2)
    sd.wait()  # Wait until recording is finished
    print("Finished")

    myrecording = np.iinfo(np.int16).max * \
        (myrecording/np.abs(myrecording).max())
    
    write(out_filename, fs, myrecording.astype(np.int16))  # Save as WAV file


if __name__ == "__main__":

    run()