def __init__(self, from_file, min_frequency=1): """Initialization method. Args: from_file (str): An input file to load the audio. min_frequency (int): Minimum frequency of individual tokens. """ logger.info('Overriding class: Corpus -> AudioCorpus.') # Overrides its parent class with any custom arguments if needed super(AudioCorpus, self).__init__(min_frequency=min_frequency) # Loads the audio from file audio = l.load_audio(from_file) # Declaring an empty list to hold audio notes self.tokens = [] # Gathering notes for step in audio: # Checking for real note if not step.is_meta and step.channel == 0 and step.type == 'note_on': # Gathering note note = step.bytes() # Saving to list self.tokens.append(str(note[1])) # Cuts the tokens based on a minimum frequency self._check_token_frequency() # Builds the vocabulary based on the tokens self._build() # Debugging some important information logger.debug( 'Tokens: %d | Type: audio | Minimum frequency: %d | Vocabulary size: %d.', len(self.tokens), self.min_frequency, len(self.vocab)) logger.info('AudioCorpus created.')
def __init__(self, from_file): """Initialization method. Args: from_file (str): An input file to load the audio. """ logger.info('Overriding class: Corpus -> AudioCorpus.') # Overrides its parent class with any custom arguments if needed super(AudioCorpus, self).__init__() # Loads the audio from file audio = l.load_audio(from_file) # Declaring an empty list to hold audio notes self.tokens = [] # Gathering notes for step in audio: # Checking for real note if not step.is_meta and step.channel == 0 and step.type == 'note_on': # Gathering note note = step.bytes() # Saving to list self.tokens.append(note[1]) # Builds the vocabulary based on the tokens self._build(self.tokens) # Debugging some important information logger.debug( f'Tokens: {len(self.tokens)} | Vocabulary Size: {len(self.vocab)} | Type: audio.' ) logger.info('AudioCorpus created.')
import nalp.utils.loader as l # Loads an input .mid file audio = l.load_audio('data/audio/sample.mid') # Printing loaded audio print(audio)