File size: 1,195 Bytes
0b32ad6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from typing import List

from .base import SequentialDataPipe
from .common_pipes import LoadAudio, RandomCrop, SetOutputKeys


class SpeakerVerificationPipe(SequentialDataPipe):
    """
    each item in the input dataset should have:
        wav_path: str
        label: str
    """

    def __init__(
        self,
        audio_sample_rate: int = 16000,
        audio_channel_reduction: str = "first",
        random_crop_secs: float = -1,
        sox_effects: List[List] = None,
    ):
        pipes = [
            LoadAudio(
                audio_sample_rate=audio_sample_rate,
                audio_channel_reduction=audio_channel_reduction,
                sox_effects=sox_effects,
            ),
        ]
        output_keys = dict(
            x="wav",
            x_len="wav_len",
            label="label",
            unique_name="id",
        )

        if random_crop_secs != -1:
            pipes.append(
                RandomCrop(sample_rate=audio_sample_rate, max_secs=random_crop_secs)
            )
            output_keys["x"] = "wav_crop"
            output_keys["x_len"] = "wav_crop_len"

        pipes.append(SetOutputKeys(output_keys))
        super().__init__(*pipes)