You can do this in Python. Here is an example using sounddevice
.
Below example records audio from microphone for #seconds
as per variable duration
which you can modify as per your requirements.
Same contents are played back using standard audio output (speakers).
This code can be scripted and played in a loop.
More on this over here
Working Code
import sounddevice as sd
import numpy as np
import scipy.io.wavfile as wav
fs=44100
duration = 10 # seconds
myrecording = sd.rec(duration * fs, samplerate=fs, channels=2, dtype='float64')
print "Recording Audio for %s seconds" %(duration)
sd.wait()
print "Audio recording complete , Playing recorded Audio"
sd.play(myrecording, fs)
sd.wait()
print "Play Audio Complete"
Output
Python 2.7.9 (default, Dec 10 2014, 12:24:55) [MSC v.1500 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>> ================================ RESTART ================================
>>>
Recording Audio for 10 seconds
Audio recording complete , Playing recorded Audio
Play Audio Complete
>>>