Beispiel #1
0
    def setUp(self):
        self.utt1 = assets.Utterance('utt-1', 'file-1')

        self.utt1.set_label_list(
            assets.LabelList(idx='alpha',
                             labels=[
                                 assets.Label('music', 0, 5),
                                 assets.Label('speech', 5, 12),
                                 assets.Label('music', 13, 15)
                             ]))

        self.utt1.set_label_list(
            assets.LabelList(idx='bravo',
                             labels=[
                                 assets.Label('music', 0, 1),
                                 assets.Label('speech', 2, 6)
                             ]))

        self.utt2 = assets.Utterance('utt-2', 'file-2')

        self.utt2.set_label_list(
            assets.LabelList(idx='alpha',
                             labels=[
                                 assets.Label('music', 0, 5),
                                 assets.Label('speech', 5, 12),
                                 assets.Label('noise', 13, 15)
                             ]))

        self.utt2.set_label_list(
            assets.LabelList(idx='bravo',
                             labels=[
                                 assets.Label('music', 0, 1),
                                 assets.Label('speech', 2, 6)
                             ]))
Beispiel #2
0
    def test_match(self):
        filter = subview.MatchingUtteranceIdxFilter(
            utterance_idxs={'a', 'b', 'd'})

        self.assertTrue(filter.match(assets.Utterance('a', 'x'), None))
        self.assertTrue(filter.match(assets.Utterance('b', 'x'), None))
        self.assertTrue(filter.match(assets.Utterance('d', 'x'), None))
        self.assertFalse(filter.match(assets.Utterance('c', 'x'), None))
        self.assertFalse(filter.match(assets.Utterance('e', 'x'), None))
Beispiel #3
0
    def test_read_samples(self):
        file = assets.File('wav', resources.sample_wav_file('wav_1.wav'))
        issuer = assets.Issuer('toni')
        utt = assets.Utterance('test',
                               file,
                               issuer=issuer,
                               start=1.0,
                               end=2.30)

        l1 = assets.Label('a', 0.15, 0.448)
        l2 = assets.Label('a', 0.5, 0.73)
        ll = assets.LabelList(labels=[l1, l2])

        utt.set_label_list(ll)

        expected, __ = librosa.core.load(file.path,
                                         sr=None,
                                         offset=1.15,
                                         duration=0.298)
        assert np.array_equal(l1.read_samples(), expected)

        expected, __ = librosa.core.load(file.path,
                                         sr=None,
                                         offset=1.5,
                                         duration=0.23)
        assert np.array_equal(l2.read_samples(), expected)
Beispiel #4
0
 def setUp(self):
     file = assets.File('wav', resources.sample_wav_file('wav_1.wav'))
     utt = assets.Utterance('utt', file, start=0.3, end=-1)
     ll = assets.LabelList()
     self.test_label = assets.Label('a', start=0.5, end=-1)
     ll.append(self.test_label)
     utt.set_label_list(ll)
Beispiel #5
0
    def test_import_utterance_no_issuer(self):
        importing_utterances = [
            assets.Utterance('a', self.ex_file, assets.Issuer('notexist'), 0,
                             10)
        ]

        with pytest.raises(ValueError):
            self.corpus.import_utterances(importing_utterances)
Beispiel #6
0
    def test_import_utterances(self):
        importing_utterances = [
            assets.Utterance('a', self.ex_file, self.ex_issuer, 0, 10),
            assets.Utterance('b', self.ex_file, self.ex_issuer, 10, 20),
            assets.Utterance('existing_utt', self.ex_file, self.ex_issuer, 20,
                             30)
        ]

        mapping = self.corpus.import_utterances(importing_utterances)

        assert self.corpus.num_utterances == 4
        assert 'a' in self.corpus.utterances.keys()
        assert 'b' in self.corpus.utterances.keys()
        assert 'existing_utt_1' in self.corpus.utterances.keys()

        assert len(mapping) == 3
        assert mapping['a'].idx == 'a'
        assert mapping['b'].idx == 'b'
        assert mapping['existing_utt'].idx == 'existing_utt_1'
Beispiel #7
0
    def new_utterance(self,
                      utterance_idx,
                      file_idx,
                      issuer_idx=None,
                      start=0,
                      end=-1):
        """
        Add a new utterance to the corpus with the given data.

        Parameters:
            file_idx (str): The file id the utterance is in.
            utterance_idx (str): The id to associate with the utterance. If None or already exists,
                                 one is generated.
            issuer_idx (str): The issuer id to associate with the utterance.
            start (float): Start of the utterance within the file [seconds].
            end (float): End of the utterance within the file [seconds]. -1 equals the end of the
                         file.

        Returns:
            Utterance: The newly added utterance.
        """

        new_utt_idx = utterance_idx

        # Check if there is a file with the given idx
        if file_idx not in self._files.keys():
            raise ValueError(
                'File with id {} does not exist!'.format(file_idx))

        # Check if issuer exists
        issuer = None

        if issuer_idx is not None:
            if issuer_idx not in self._issuers.keys():
                raise ValueError(
                    'Issuer with id {} does not exist!'.format(issuer_idx))
            else:
                issuer = self._issuers[issuer_idx]

        # Add index to idx if already existing
        if new_utt_idx in self._utterances.keys():
            new_utt_idx = naming.index_name_if_in_list(new_utt_idx,
                                                       self._utterances.keys())

        new_utt = assets.Utterance(new_utt_idx,
                                   self.files[file_idx],
                                   issuer=issuer,
                                   start=start,
                                   end=end)

        self._utterances[new_utt_idx] = new_utt

        return new_utt
Beispiel #8
0
    def setUp(self):
        self.tempdir = tempfile.mkdtemp()
        self.corpus = audiomate.Corpus(self.tempdir)

        self.ex_file = assets.File('existing_file', '../any/path.wav')
        self.ex_issuer = assets.Issuer('existing_issuer')
        self.ex_utterance = assets.Utterance('existing_utt',
                                             self.ex_file,
                                             issuer=self.ex_issuer)

        self.corpus.files['existing_file'] = self.ex_file
        self.corpus.issuers['existing_issuer'] = self.ex_issuer
        self.corpus.utterances['existing_utt'] = self.ex_utterance
Beispiel #9
0
    def test_encode_utterance_takes_lower_index_first(self):
        file = assets.File('file-idx', resources.sample_wav_file('wav_1.wav'))
        utt = assets.Utterance('utt-idx', file, start=0, end=5)
        ll = assets.LabelList(
            labels=[assets.Label('music', 0, 3),
                    assets.Label('speech', 3, 5)])
        utt.set_label_list(ll)

        enc = label_encoding.FrameOrdinalEncoder(
            ['speech', 'music', 'noise'],
            frame_settings=units.FrameSettings(32000, 16000),
            sr=16000)

        actual = enc.encode(utt)
        expected = np.array([1, 1, 0, 0]).astype(np.int)

        assert np.array_equal(expected, actual)
Beispiel #10
0
    def setUp(self):
        self.ll_1 = assets.LabelList(idx='alpha',
                                     labels=[
                                         assets.Label('a', 3.2, 4.5),
                                         assets.Label('b', 5.1, 8.9),
                                         assets.Label('c', 7.2, 10.5),
                                         assets.Label('d', 10.5, 14),
                                         assets.Label('d', 15, 18)
                                     ])

        self.ll_2 = assets.LabelList(idx='bravo',
                                     labels=[
                                         assets.Label('a', 1.0, 4.2),
                                         assets.Label('e', 4.2, 7.9),
                                         assets.Label('c', 7.2, 10.5),
                                         assets.Label('f', 10.5, 14),
                                         assets.Label('d', 15, 17.3)
                                     ])

        self.ll_duplicate_idx = assets.LabelList(
            idx='charlie',
            labels=[assets.Label('t', 1.0, 4.2),
                    assets.Label('h', 4.2, 7.9)])

        self.ll_3 = assets.LabelList(
            idx='charlie',
            labels=[assets.Label('a', 1.0, 4.2),
                    assets.Label('g', 4.2, 7.9)])

        self.file = assets.File('wav', resources.sample_wav_file('wav_1.wav'))
        self.issuer = assets.Issuer('toni')
        self.utt = assets.Utterance('test',
                                    self.file,
                                    issuer=self.issuer,
                                    start=1.25,
                                    end=1.30,
                                    label_lists=[
                                        self.ll_1, self.ll_2,
                                        self.ll_duplicate_idx, self.ll_3
                                    ])
Beispiel #11
0
 def test_duration_end_of_file(self):
     utt = assets.Utterance('utt', self.file, start=0.3, end=-1)
     assert utt.duration == pytest.approx(2.2951875)
Beispiel #12
0
 def test_end_abs_end_of_file(self):
     utt = assets.Utterance('utt', self.file, start=0.3, end=-1)
     assert utt.end_abs == pytest.approx(2.5951875)
Beispiel #13
0
    def test_end_abs(self):
        label = assets.Label('a', 2, 5)
        ll = assets.LabelList(labels=[label])
        assets.Utterance('utt-1', None, start=1, end=19, label_lists=[ll])

        assert label.end_abs == 6
Beispiel #14
0
def sample_utterance():
    file = assets.File('test_file', resources.sample_wav_file('wav_1.wav'))
    utterance = assets.Utterance('test', file)
    return utterance