import time i = 0 def recorder_callback(data,state): global i i += 1 if state == Audio.STATE_ENUM.STOP: print "CB: Recorder stopped" return; if state == Audio.STATE_ENUM.STARTING: print "CB: Recorder started" if data is not None: print "CB: recorded data %d bytes - chunk %d" % (len(data),i) pass a = Audio(record_callback=recorder_callback) a.open() a.start_record(record_time_threshold=5) while a.recorder_stream.is_active(): time.sleep(0.1) #loop and wait for 5 seconds a.stop_record() a.close()