def _test_copy_wave_file_channel_aux(
         self, input_file_name, channel_num, chunk_size=None):
     
     input_file_path = _create_file_path(input_file_name)
     output_file_path = _create_file_path(_TEST_FILE_NAME)
     
     expected_samples, expected_sample_rate = \
         audio_file_utils.read_wave_file(input_file_path)
     expected_samples = expected_samples[channel_num]
         
     try:
         
         if chunk_size is None:
             audio_file_utils.copy_wave_file_channel(
                 input_file_path, channel_num, output_file_path)
             
         else:
             audio_file_utils.copy_wave_file_channel(
                 input_file_path, channel_num, output_file_path,
                 chunk_size)
         
         samples, sample_rate = \
             audio_file_utils.read_wave_file(output_file_path)
             
         self.assertEqual(samples.shape[0], 1)
         self.assertEqual(samples.shape[1], len(expected_samples))
         self.assertEqual(sample_rate, expected_sample_rate)
         self.assertTrue(all(samples[0] == expected_samples))
         
     finally:
         os_utils.delete_file(output_file_path)
Beispiel #2
0
    def complete_detection(self):
        """
        Completes detection after the `detect` method has been called
        for all input.
        """

        # print('_Detector.complete_detection')

        # Close wave writer and wave file.
        self._audio_file_writer.close()
        self._audio_file.close()

        with tempfile.TemporaryDirectory() as output_dir_path:

            # output_dir_path = '/Users/harold/Desktop/BirdVoxDetect Output'

            audio_file_path = self._audio_file.name

            birdvoxdetect.process_file(
                audio_file_path,
                bva_threshold=1,
                detector_name=self.settings.detector_name,
                threshold=self.settings.threshold,
                logger_level=logging.WARN,
                output_dir=output_dir_path)

            output_file_path = self._get_output_file_path(
                output_dir_path, audio_file_path)

            self._process_detector_output(output_file_path)

        os_utils.delete_file(audio_file_path)

        self._listener.complete_processing()
 def _test_copy_wave_file_channel_aux(
         self, input_file_name, channel_num, chunk_size=None):
     
     input_file_path = _create_file_path(input_file_name)
     output_file_path = _create_file_path(_TEST_FILE_NAME)
     
     expected_samples, expected_sample_rate = \
         audio_file_utils.read_wave_file(input_file_path)
     expected_samples = expected_samples[channel_num]
         
     try:
         
         if chunk_size is None:
             audio_file_utils.copy_wave_file_channel(
                 input_file_path, channel_num, output_file_path)
             
         else:
             audio_file_utils.copy_wave_file_channel(
                 input_file_path, channel_num, output_file_path,
                 chunk_size)
         
         samples, sample_rate = \
             audio_file_utils.read_wave_file(output_file_path)
             
         self.assertEqual(samples.shape[0], 1)
         self.assertEqual(samples.shape[1], len(expected_samples))
         self.assertEqual(sample_rate, expected_sample_rate)
         self.assertTrue(all(samples[0] == expected_samples))
         
     finally:
         os_utils.delete_file(output_file_path)
 def test_write_wave_file(self):
     
     path = _create_file_path(_TEST_FILE_NAME)
     
     for _, num_channels, length, sample_rate in _TEST_CASES:
         
         samples = _create_samples(num_channels, length)
         audio_file_utils.write_wave_file(path, samples, sample_rate)
         
         try:
             self._assert_wave_file(
                 _TEST_FILE_NAME, num_channels, length, sample_rate)
         finally:
             os_utils.delete_file(path)
 def test_write_wave_file(self):
     
     path = _create_file_path(_TEST_FILE_NAME)
     
     for _, num_channels, length, sample_rate in _TEST_CASES:
         
         samples = _create_samples(num_channels, length)
         audio_file_utils.write_wave_file(path, samples, sample_rate)
         
         try:
             self._assert_wave_file(
                 _TEST_FILE_NAME, num_channels, length, sample_rate)
         finally:
             os_utils.delete_file(path)
Beispiel #6
0
 def delete_audio_file(self, clip):
     
     """
     Deletes the audio file of the specified clip.
     
     If the audio file is not present, this method does nothing.
     
     Parameters
     ----------
     clip : Clip
         the clip whose audio file should be deleted.
     """
     
     path = self.get_audio_file_path(clip)
     os_utils.delete_file(path)
Beispiel #7
0
 def delete_audio_file(self, clip):
     
     """
     Deletes the audio file of the specified clip.
     
     If the audio file is not present, this method does nothing.
     
     Parameters
     ----------
     clip : Clip
         the clip whose audio file should be deleted.
     """
     
     path = self.get_audio_file_path(clip)
     os_utils.delete_file(path)
 def _prepare_output_dir(self):
     
     name = self.name
     
     self._logger.info(
         'Clearing {} files from output directory "{}"...'.format(
             name, _OUTPUT_DIR_PATH))
 
     log_path = self._detector_log_path
     os_utils.delete_file(log_path)
     
     pattern = _CLIP_FILE_NAME_PATTERN_FORMAT.format(name)
     os_utils.delete_files(_OUTPUT_DIR_PATH, pattern)
     
     self._logger.info(
         'Creating empty detector log file "{}"...'.format(log_path))
     os_utils.create_file(log_path)
    def _prepare_output_dir(self):

        name = self.name

        self._logger.info(
            'Clearing {} files from output directory "{}"...'.format(
                name, _OUTPUT_DIR_PATH))

        log_path = self._detector_log_path
        os_utils.delete_file(log_path)

        pattern = _CLIP_FILE_NAME_PATTERN_FORMAT.format(name)
        os_utils.delete_files(_OUTPUT_DIR_PATH, pattern)

        self._logger.info(
            'Creating empty detector log file "{}"...'.format(log_path))
        os_utils.create_file(log_path)
 def test_write_single_channel_wave_file(self):
     
     path = _create_file_path(_TEST_FILE_NAME)
     
     for _, num_channels, length, sample_rate in _TEST_CASES:
         
         if num_channels == 1:
             
             samples = _create_samples(num_channels, length)
             
             # Flatten two-dimensional sample array to a single dimension.
             samples = samples.flatten()
             
             audio_file_utils.write_wave_file(path, samples, sample_rate)
             
             try:
                 self._assert_wave_file(
                     _TEST_FILE_NAME, num_channels, length, sample_rate)
             finally:
                 os_utils.delete_file(path)
    def test_write_wave_file_samples(self):
        
        channel_counts = (1, 2)
        sample_rate = 24000
        sample_size = 16
        file_size = 20
        
        cases = [
            
            # in-order writes
            [(0, 10), (10, 5), (15, 5)],
            
            # out-of-order writes
            [(0, 5), (20, 10), (5, 10), (15, 5)]

        ]

        path = _create_file_path(_TEST_FILE_NAME)
        
        for writes in cases:
            
            for channel_count in channel_counts:
            
                audio_file_utils.write_empty_wave_file(
                    path, channel_count, sample_rate, sample_size)
                
                for start_index, frame_count in writes:
                    
                    samples = _create_samples(channel_count, frame_count)
                    samples += start_index
                    
                    audio_file_utils.write_wave_file_samples(
                        path, start_index, samples)
                    
                try:
                    self._assert_wave_file(
                        _TEST_FILE_NAME, channel_count, file_size, sample_rate)
                finally:
                    os_utils.delete_file(path)
Beispiel #12
0
    def complete_detection(self):
        
        """
        Completes detection after the `detect` method has been called
        for all input.
        """
        
        # print('_Detector.complete_detection')
        
        # Close wave writer and wave file.
        self._audio_file_writer.close()
        self._audio_file.close()
        
        with tempfile.TemporaryDirectory() as output_dir_path:
            
            # output_dir_path = '/Users/harold/Desktop/BirdVoxDetect Output'
            
            audio_file_path = self._audio_file.name
            
            if self.settings.threshold_adaptation_enabled:
                detector_name = \
                    'birdvoxdetect_pcen_cnn_adaptive-threshold-T1800'
            else:
                detector_name = 'birdvoxdetect_pcen_cnn'
            
            birdvoxdetect.process_file(
                audio_file_path,
                detector_name=detector_name,
                threshold=self.settings.threshold,
                output_dir=output_dir_path)
 
            timestamp_file_path = self._get_timestamp_file_path(
                output_dir_path, audio_file_path)
            
            self._process_timestamps(timestamp_file_path)
                
        os_utils.delete_file(audio_file_path)
        
        self._listener.complete_processing()
Beispiel #13
0
    def complete_detection(self):
        
        """
        Completes detection after the `detect` method has been called
        for all input.
        """
        
        # print('_Detector.complete_detection')
        
        # Close wave writer and wave file.
        self._audio_file_writer.close()
        self._audio_file.close()
        
        with tempfile.TemporaryDirectory() as output_dir_path:
            
            # output_dir_path = '/Users/harold/Desktop/BirdVoxDetect Output'
            
            audio_file_path = self._audio_file.name
            
            if self.settings.threshold_adaptation_enabled:
                detector_name = \
                    'birdvoxdetect_pcen_cnn_adaptive-threshold-T1800'
            else:
                detector_name = 'birdvoxdetect_pcen_cnn'
            
            birdvoxdetect.process_file(
                audio_file_path,
                detector_name=detector_name,
                threshold=self.settings.threshold,
                output_dir=output_dir_path)
 
            timestamp_file_path = self._get_timestamp_file_path(
                output_dir_path, audio_file_path)
            
            self._process_timestamps(timestamp_file_path)
                
        os_utils.delete_file(audio_file_path)
        
        self._listener.complete_processing()
    def test_write_empty_wave_file_in_parts(self):
        
        sample_size = 16
        frame_count = 0
        
        cases = [
            (1, 24000),
            (2, 24000),
            (1, 48000)
        ]
        
        for channel_count, sample_rate in cases:
            
            path = _create_file_path(_TEST_FILE_NAME)
        
            audio_file_utils.write_empty_wave_file(
                path, channel_count, sample_rate, sample_size)

            try:
                self._assert_wave_file(
                    _TEST_FILE_NAME, channel_count, frame_count, sample_rate)
            finally:
                os_utils.delete_file(path)
 def _delete_file(self, file_path):
     try:
         os_utils.delete_file(file_path)
     except Exception as e:
         self._logger.error(str(e))
 def _delete_file(self, file_path):
     try:
         os_utils.delete_file(file_path)
     except Exception as e:
         self._logger.error(str(e))