class _Recorder(object): """Class for internal object to make an audio recording using pyo. Never needed by end-users; only used internally in __init__: self.recorder = _Recorder(None) # instantiate, global Then in record(), do: self.recorder.run(filename, sec) This sets recording parameters, starts recording. To stop a recording that is in progress, do self.stop() This class never handles blocking; AudioCapture has to do that. Motivation: Doing pyo Record from within a function worked most of the time, but failed catastrophically ~1% of time with a bus error. Seemed to be due to a namespace scoping issue, which using globals seemed to fix; see pyo mailing list, 7 April 2012. This draws heavily on Olivier Belanger's solution. """ def __init__(self): self.running = False def run(self, filename, sec, sampletype=0, buffering=16, chnl=0, chnls=2): self.running = True inputter = Input(chnl=chnl, mul=1) # chnl from pyo.pa_get_input_devices() self.recorder = Record(inputter, filename, chnls=chnls, fileformat=0, sampletype=sampletype, buffering=buffering) Clean_objects(sec, self.recorder).start() # handles recording offset threading.Timer(sec, self._stop).start() # set running flag False def stop(self): self.recorder.stop() self._stop() def _stop(self): self.running = False