Ejemplo n.º 1
0
 def test_split_padded_simple(self):
     """
     Test split_padded method with simple arrays that divide evenly
     into the segments without any padding.
     """
     arr1000 = create_1d_array(1000)
     samplesize=500
     arrays = _split_padded(arr1000,samplesize)
     for a in arrays:
         self.assertEqual(len(a),samplesize)
     self.assertEqual(len(arrays),2)
Ejemplo n.º 2
0
    def test_split_padded_array_needs_padding(self):
        """
        Test split_padded method with 1d array and samplesize that needs
        padding.
        """
        arr1000 = create_1d_array(1000)
        samplesize=300
        arrays = _split_padded(arr1000,samplesize)
        for a in arrays:
            self.assertEqual(len(a),samplesize)
        self.assertEqual(len(arrays),4)

        # verify that the padding is done at the following range
        for i in range(100,300):
            self.assertEqual(arrays[3][i],0)
Ejemplo n.º 3
0
 def generate_classless_samples(self,relative_path=''):
     """
     TestSamples are derived from TestRecordings. Typically each TestRecording
     is annotated with an associated json file, but this is not the case for
     live test recordings. This method will generate TestSamples without knowing
     the class of each audio segment within it.
     """
     (rate,audio) = wav.read(self.path)
     segments = _split_padded(audio,rate)
     samples = []
     for s in range(0,len(segments)):
         root = self.path.replace(self.name,'')
         sample_path = root+relative_path+self._create_sample_name(s,default_key='UNKNOWN')
         save_sample(sample_path,segments[s],rate)
         samples.append(TestSample(sample_path))
     return samples
Ejemplo n.º 4
0
 def generate_samples(self,relative_path=''):
     """
     TestSamples are derived from TestRecordings. This method will generate the
     actual sample wav files based on the test recording audio file. The metadata
     must exist and be valid in order for this method to succeed.
     """
     if not self.loaded:
         self.load_metadata()
     if not self.valid:
         raise ValueError('Cannot generate samples from invalid testrecording')
     else:
         (rate,audio) = wav.read(self.path)
         segments = _split_padded(audio,rate)
         samples = []
         for s in range(0,len(segments)):
             root = self.path.replace(self.name,'')
             sample_path = root+relative_path+self._create_sample_name(s)
             save_sample(sample_path,segments[s],rate)
             samples.append(TestSample(sample_path))
         return samples