pybinsim/soundhandling.py
def read_sound_files(self, sound_file_list):
        """load all files for the audio installation"""
        sound_file_list = str.split(sound_file_list, '#')
        self.soundFileList = sound_file_list
        self.log.info("Audio Files: {}".format(str(self.soundFileList)))

        for sound in self.soundFileList:
            self.log.info('Loading new sound file')

            #get id and type of soundfile
            match = re.search(r"(?P<id>[0-9]{3})(?P<type>[slt])ID_", sound)
            key = match.group('id')
            event_type = match.group('type')

            audio_file_data, fs = sf.read(sound, dtype='float32', )
            assert fs == self.fs

            self.log.debug("audio_file_data: {} MB".format(audio_file_data.nbytes // 1024 // 1024))
            self.sound_file = np.asmatrix(audio_file_data)

            # free data
            audio_file_data = None

            if self.sound_file.shape[0] > self.sound_file.shape[1]:
                self.sound_file = self.sound_file.transpose()

            self.active_channels = self.sound_file.shape[0]

            if self.sound_file.shape[1] % self.chunk_size != 0:
                length_diff = self.chunk_size - (self.sound_file.shape[1] % self.chunk_size)
                zeros = np.zeros((self.sound_file.shape[0], length_diff), dtype=np.float32)

                self.log.debug("Zeros size: {} Byte".format(zeros.nbytes))
                self.log.debug("Zeros shape: {} ({})".format(zeros.shape, zeros.dtype))
                self.log.debug("Soundfile size: {} MiB".format(self.sound_file.nbytes // 1024 // 1024))
                self.log.debug("Soundfile shape: {} ({})".format(self.sound_file.shape, self.sound_file.dtype))
                self.sound_file = np.concatenate(
                    (self.sound_file, zeros),
                    1
                )
                self.log.debug("Soundfile size after concat: {} MiB".format(self.sound_file.nbytes // 1024 // 1024))
                self.log.debug(
                    "Soundfile shape after concat: {} ({})".format(self.sound_file.shape, self.sound_file.dtype))

            #collect SoundEvent in dictionary
            self.sound_events[key] = SoundEvent(self.sound_file, key, event_type, self.chunk_size, self.n_channels)
            self.log.info('Loaded new sound file\n')
load all files for the audio installation
load all files for the audio installation
load all files for the audio installation
def read_sound_files(self, sound_file_list):
        sound_file_list = str.split(sound_file_list, '#')
        self.soundFileList = sound_file_list
        self.log.info("Audio Files: {}".format(str(self.soundFileList)))
        for sound in self.soundFileList:
            self.log.info('Loading new sound file')
            match = re.search(r"(?P<id>[0-9]{3})(?P<type>[slt])ID_", sound)
            key = match.group('id')
            event_type = match.group('type')
            audio_file_data, fs = sf.read(sound, dtype='float32', )
            assert fs == self.fs
            self.log.debug("audio_file_data: {} MB".format(audio_file_data.nbytes // 1024 // 1024))
            self.sound_file = np.asmatrix(audio_file_data)
            audio_file_data = None
            if self.sound_file.shape[0] > self.sound_file.shape[1]:
                self.sound_file = self.sound_file.transpose()
            self.active_channels = self.sound_file.shape[0]
            if self.sound_file.shape[1] % self.chunk_size != 0:
                length_diff = self.chunk_size - (self.sound_file.shape[1] % self.chunk_size)
                zeros = np.zeros((self.sound_file.shape[0], length_diff), dtype=np.float32)
                self.log.debug("Zeros size: {} Byte".format(zeros.nbytes))
                self.log.debug("Zeros shape: {} ({})".format(zeros.shape, zeros.dtype))
                self.log.debug("Soundfile size: {} MiB".format(self.sound_file.nbytes // 1024 // 1024))
                self.log.debug("Soundfile shape: {} ({})".format(self.sound_file.shape, self.sound_file.dtype))
                self.sound_file = np.concatenate(
                    (self.sound_file, zeros),
                    1
                )
                self.log.debug("Soundfile size after concat: {} MiB".format(self.sound_file.nbytes // 1024 // 1024))
                self.log.debug(
                    "Soundfile shape after concat: {} ({})".format(self.sound_file.shape, self.sound_file.dtype))
            self.sound_events[key] = SoundEvent(self.sound_file, key, event_type, self.chunk_size, self.n_channels)
            self.log.info('Loaded new sound file\n')
def read_sound_files ( self , sound_file_list ) : sound_file_list = str . split ( sound_file_list , '#' ) self . soundFileList = sound_file_list self . log . info ( "Audio Files: {}" . format ( str ( self . soundFileList ) ) ) for sound in self . soundFileList : self . log . info ( 'Loading new sound file' ) match = re . search ( r"(?P<id>[0-9]{3})(?P<type>[slt])ID_" , sound ) key = match . group ( 'id' ) event_type = match . group ( 'type' ) audio_file_data , fs = sf . read ( sound , dtype = 'float32' , ) assert fs == self . fs self . log . debug ( "audio_file_data: {} MB" . format ( audio_file_data . nbytes // 1024 // 1024 ) ) self . sound_file = np . asmatrix ( audio_file_data ) audio_file_data = None if self . sound_file . shape [ 0 ] > self . sound_file . shape [ 1 ] : self . sound_file = self . sound_file . transpose ( ) self . active_channels = self . sound_file . shape [ 0 ] if self . sound_file . shape [ 1 ] % self . chunk_size != 0 : length_diff = self . chunk_size - ( self . sound_file . shape [ 1 ] % self . chunk_size ) zeros = np . zeros ( ( self . sound_file . shape [ 0 ] , length_diff ) , dtype = np . float32 ) self . log . debug ( "Zeros size: {} Byte" . format ( zeros . nbytes ) ) self . log . debug ( "Zeros shape: {} ({})" . format ( zeros . shape , zeros . dtype ) ) self . log . debug ( "Soundfile size: {} MiB" . format ( self . sound_file . nbytes // 1024 // 1024 ) ) self . log . debug ( "Soundfile shape: {} ({})" . format ( self . sound_file . shape , self . sound_file . dtype ) ) self . sound_file = np . concatenate ( ( self . sound_file , zeros ) , 1 ) self . log . debug ( "Soundfile size after concat: {} MiB" . format ( self . sound_file . nbytes // 1024 // 1024 ) ) self . log . debug ( "Soundfile shape after concat: {} ({})" . format ( self . sound_file . shape , self . sound_file . dtype ) ) self . sound_events [ key ] = SoundEvent ( self . sound_file , key , event_type , self . chunk_size , self . n_channels ) self . log . info ( 'Loaded new sound file\n' )
load all files for the audio installation
load all files for the audio installation
"""load all files for the audio installation""" #get id and type of soundfile # free data #collect SoundEvent in dictionary
self
sound_file_list