Record sound from microphone

This works if you got "PortAudio" on your system.

import audiofile as af
import sounddevice as sd

def record_audio(filename, seconds):
    fs = 16000
    print("recording {} ({}s) ...".format(filename, seconds))
    y = sd.rec(int(seconds * fs), samplerate=fs, channels=1)
    y = y.T
    af.write(filename, y, fs)
    print("  ... saved to {}".format(filename))

Leave a Reply

Your email address will not be published. Required fields are marked *