Ejemplo n.º 1
0
    def __init__(self, name='mic', file='', saveDir=''):
        """
        :Parameters:
                name :
                    Stem for the output file, also used in logging.
                file :
                    optional file name to use; default = 'name-onsetTimeEpoch.wav'
                saveDir :
                    Directory to use for output .wav files.
                    If a saveDir is given, it will return 'saveDir/file'. 
                    If no saveDir, then return abspath(file)
        """
        self.name = name
        self.saveDir = saveDir
        if file:
            self.wavOutFilename = file
        else:
            self.wavOutFilename = os.path.join(self.saveDir, name + ONSET_TIME_HERE +'.wav')
        if not self.saveDir:
            self.wavOutFilename = os.path.abspath(self.wavOutFilename)

        self.onset = None # becomes onset time, used in filename
        self.savedFile = False # becomes saved file name
        self.status = NOT_STARTED # for Builder component
        
        # pyo server good to go? 
        if not serverCreated():
            raise AttributeError('pyo server not created')
        if not serverBooted():
            raise AttributeError('pyo server not booted')
        
        self.loggingId = self.__class__.__name__
        if self.name:
            self.loggingId += ' ' + self.name
    def __init__(self,
                 name='mic',
                 filename='',
                 saveDir='',
                 sampletype=0,
                 buffering=16,
                 chnl=0):
        """
        :Parameters:
            name :
                Stem for the output file, also used in logging.
            file :
                optional file name to use; default = 'name-onsetTimeEpoch.wav'
            saveDir :
                Directory to use for output .wav files.
                If a saveDir is given, it will return 'saveDir/file'.
                If no saveDir, then return abspath(file)
            sampletype : bit depth
                pyo recording option: 0=16 bits int, 1=24 bits int; 2=32 bits int
        """
        if not haveMic:
            raise MicrophoneError(
                'Need to call microphone.switchOn() before AudioCapture or AdvancedCapture'
            )
        self.name = name
        self.saveDir = saveDir
        if filename:
            self.wavOutFilename = filename
        else:
            self.wavOutFilename = os.path.join(self.saveDir, name + '.wav')
        if not self.saveDir:
            self.wavOutFilename = os.path.abspath(self.wavOutFilename)
        else:
            if not os.path.isdir(self.saveDir):
                os.makedirs(self.saveDir, 0770)

        self.onset = None  # becomes onset time, used in filename
        self.savedFile = False  # becomes saved file name
        self.status = NOT_STARTED  # for Builder component

        # pyo server good to go?
        if not serverCreated():
            raise AttributeError('pyo server not created')
        if not serverBooted():
            raise AttributeError('pyo server not booted')

        self.loggingId = self.__class__.__name__
        if self.name:
            self.loggingId += ' ' + self.name

        # the recorder object needs to persist, or else get bus errors:
        self.recorder = self._Recorder()
        self.options = {
            'sampletype': sampletype,
            'buffering': buffering,
            'chnl': chnl
        }
Ejemplo n.º 3
0
    def __init__(
        self, name="mic", filename="", saveDir="", sampletype=0, buffering=16, chnl=0, stereo=True, autoLog=True
    ):
        """
        :Parameters:
            name :
                Stem for the output file, also used in logging.
            filename :
                optional file name to use; default = 'name-onsetTimeEpoch.wav'
            saveDir :
                Directory to use for output .wav files.
                If a saveDir is given, it will return 'saveDir/file'.
                If no saveDir, then return abspath(file)
            sampletype : bit depth
                pyo recording option: 0=16 bits int, 1=24 bits int; 2=32 bits int
            buffering : pyo argument
            chnl : which audio input channel to record (default=0)
            stereo : how many channels to record (default True, stereo; False = mono)
        """
        if not haveMic:
            raise MicrophoneError("Need to call microphone.switchOn() before AudioCapture or AdvancedCapture")
        self.name = name
        self.saveDir = saveDir
        if filename:
            self.wavOutFilename = filename
        else:
            self.wavOutFilename = os.path.join(self.saveDir, name + ".wav")
        if not self.saveDir:
            self.wavOutFilename = os.path.abspath(self.wavOutFilename)
        else:
            if not os.path.isdir(self.saveDir):
                os.makedirs(self.saveDir, 0770)

        self.onset = None  # becomes onset time, used in filename
        self.savedFile = False  # becomes saved file name
        self.status = NOT_STARTED  # for Builder component

        # pyo server good to go?
        if not serverCreated():
            raise AttributeError("pyo server not created")
        if not serverBooted():
            raise AttributeError("pyo server not booted")

        self.autoLog = autoLog
        self.loggingId = self.__class__.__name__
        if self.name:
            self.loggingId += " " + self.name

        # the recorder object needs to persist, or else get bus errors:
        self.recorder = self._Recorder()
        self.options = {
            "sampletype": sampletype,
            "buffering": buffering,
            "chnl": chnl,
            "chnls": 1 + int(stereo == True),
        }
Ejemplo n.º 4
0
def switchOff():
    """Must explicitly switch off the microphone when done.
    """
    t0 = time.time()
    global pyoServer, pyoSamplingRate
    if serverBooted():
        pyoServer.stop()
        time.sleep(.25) # give it a chance to stop before shutdown()
    if serverCreated():
        pyoServer.shutdown()
    del pyoSamplingRate
    logging.exp('%s: switch off took %.3fs' % (__file__.strip('.py'), time.time() - t0))
Ejemplo n.º 5
0
def switchOff():
    """Its good to explicitly switch off the microphone when done (in order to avoid
    a segmentation fault). core.quit() also tries to switchOff if needed, but best to
    do so explicitly.
    """
    t0 = core.getTime()
    global haveMic
    haveMic = False
    global pyoServer
    if serverBooted():
        pyoServer.stop()
        core.wait(.25) # give it a chance to stop before shutdown(), avoid seg fault
    if serverCreated():
        pyoServer.shutdown()
        del core.pyoServers[core.pyoServers.index(pyoServer)]
    logging.exp('%s: switch off took %.3fs' % (__file__.strip('.py'), core.getTime() - t0))
Ejemplo n.º 6
0
    def __init__(self, name='mic', filename='', saveDir='', sampletype=0,
                 buffering=16, chnl=0):
        """
        :Parameters:
            name :
                Stem for the output file, also used in logging.
            file :
                optional file name to use; default = 'name-onsetTimeEpoch.wav'
            saveDir :
                Directory to use for output .wav files.
                If a saveDir is given, it will return 'saveDir/file'.
                If no saveDir, then return abspath(file)
            sampletype : bit depth
                pyo recording option: 0=16 bits int, 1=24 bits int; 2=32 bits int
        """
        if not haveMic:
            raise MicrophoneError('Need to call microphone.switchOn() before AudioCapture or AdvancedCapture')
        self.name = name
        self.saveDir = saveDir
        if filename:
            self.wavOutFilename = filename
        else:
            self.wavOutFilename = os.path.join(self.saveDir, name + '.wav')
        if not self.saveDir:
            self.wavOutFilename = os.path.abspath(self.wavOutFilename)
        else:
            if not os.path.isdir(self.saveDir):
                os.makedirs(self.saveDir, 0770)

        self.onset = None # becomes onset time, used in filename
        self.savedFile = False # becomes saved file name
        self.status = NOT_STARTED # for Builder component

        # pyo server good to go?
        if not serverCreated():
            raise AttributeError('pyo server not created')
        if not serverBooted():
            raise AttributeError('pyo server not booted')

        self.loggingId = self.__class__.__name__
        if self.name:
            self.loggingId += ' ' + self.name

        # the recorder object needs to persist, or else get bus errors:
        self.recorder = self._Recorder()
        self.options = {'sampletype': sampletype, 'buffering': buffering, 'chnl': chnl}
Ejemplo n.º 7
0
def switchOff():
    """Its good to explicitly switch off the microphone when done (in order to avoid
    a segmentation fault). core.quit() also tries to switchOff if needed, but best to
    do so explicitly.
    """
    t0 = core.getTime()
    global haveMic
    haveMic = False
    global pyoServer
    if serverBooted():
        pyoServer.stop()
        core.wait(
            .25)  # give it a chance to stop before shutdown(), avoid seg fault
    if serverCreated():
        pyoServer.shutdown()
        del core.pyoServers[core.pyoServers.index(pyoServer)]
    logging.exp('%s: switch off took %.3fs' %
                (__file__.strip('.py'), core.getTime() - t0))
Ejemplo n.º 8
0
 def beat(self):
   while True:
     self._osc.send(self._msg)
     sleep(self._del)
     if not serverBooted(): break