def train_on_audio(self, fn: str):
        """Run through a single audio file"""
        save_test = random() > 0.8
        audio = load_audio(fn)
        num_chunks = len(audio) // self.args.chunk_size

        self.listener.clear()

        for i, chunk in enumerate(chunk_audio(audio, self.args.chunk_size)):
            print('\r' + str(i * 100. / num_chunks) + '%', end='', flush=True)
            self.audio_buffer = np.concatenate((self.audio_buffer[len(chunk):], chunk))
            conf = self.listener.update(chunk)
            if conf > self.args.threshold:
                self.samples_since_train += 1
                name = splitext(basename(fn))[0] + '-' + str(i) + '.wav'
                name = join(self.args.folder, 'test' if save_test else '', 'not-wake-word',
                            'generated', name)
                save_audio(name, self.audio_buffer)
                print()
                print('Saved to:', name)

            if not save_test and self.samples_since_train >= self.args.delay_samples and \
                    self.args.epochs > 0:
                self.samples_since_train = 0
                self.retrain()
def train_on_audio ( self , fn : str ) : save_test = random ( ) > 0.8 audio = load_audio ( fn ) num_chunks = len ( audio ) // self . args . chunk_size self . listener . clear ( ) for i , chunk in enumerate ( chunk_audio ( audio , self . args . chunk_size ) ) : print ( '\r' + str ( i * 100. / num_chunks ) + '%' , end = '' , flush = True ) self . audio_buffer = np . concatenate ( ( self . audio_buffer [ len ( chunk ) : ] , chunk ) ) conf = self . listener . update ( chunk ) if conf > self . args . threshold : self . samples_since_train += 1 name = splitext ( basename ( fn ) ) [ 0 ] + '-' + str ( i ) + '.wav' name = join ( self . args . folder , 'test' if save_test else '' , 'not-wake-word' , 'generated' , name ) save_audio ( name , self . audio_buffer ) print ( ) print ( 'Saved to:' , name ) if not save_test and self . samples_since_train >= self . args . delay_samples and self . args . epochs > 0 : self . samples_since_train = 0 self . retrain ( )
Run through a single audio file