Ejemplo n.º 1
0
    def __init__(self,
                 manifests_files: Union[str, List[str]],
                 is_regression_task=False,
                 *args,
                 **kwargs):
        """Parse lists of audio files, durations and transcripts texts.

        Args:
            manifests_files: Either single string file or list of such -
                manifests to yield items from.
            is_regression_task: It's a regression task
            *args: Args to pass to `SpeechLabel` constructor.
            **kwargs: Kwargs to pass to `SpeechLabel` constructor.
        """
        audio_files, durations, labels, offsets = [], [], [], []

        for item in manifest.item_iter(manifests_files,
                                       parse_func=self.__parse_item):
            audio_files.append(item['audio_file'])
            durations.append(item['duration'])
            if not is_regression_task:
                labels.append(item['label'])
            else:
                labels.append(float(item['label']))

            offsets.append(item['offset'])

        super().__init__(audio_files, durations, labels, offsets, *args,
                         **kwargs)
Ejemplo n.º 2
0
    def __init__(self,
                 manifests_files: Union[str, List[str]],
                 manifest_line_parser: Callable[[str, Optional[str]],
                                                Dict[str, Any]] = None,
                 *args,
                 **kwargs):
        """Parse lists of audio files, durations and transcripts texts.

        Args:
            manifests_files: Either single string file or list of such -
                manifests to yield items from.
            manifest_line_parser: Callable function to parse a line in the manifest file.
            *args: Args to pass to `AudioText` constructor.
            **kwargs: Kwargs to pass to `AudioText` constructor.
        """

        ids, audio_files, durations, texts, offsets, speakers, orig_srs = [], [], [], [], [], [], []
        for item in manifest.item_iter(manifests_files, manifest_line_parser):
            ids.append(item['id'])
            audio_files.append(item['audio_file'])
            durations.append(item['duration'])
            texts.append(item['text'])
            offsets.append(item['offset'])
            speakers.append(item['speaker'])
            orig_srs.append(item['orig_sr'])

        super().__init__(ids, audio_files, durations, texts, offsets, speakers,
                         orig_srs, *args, **kwargs)
Ejemplo n.º 3
0
    def __parse_texts(file: str) -> List[str]:
        if not os.path.exists(file):
            raise ValueError('Provided texts file does not exists!')

        _, ext = os.path.splitext(file)
        if ext == '.csv':
            texts = pd.read_csv(file)['transcript'].tolist()
        elif ext == '.json':  # Not really a correct json.
            texts = list(item['text'] for item in manifest.item_iter(file))
        else:
            with open(file, 'r') as f:
                texts = f.readlines()

        return texts
Ejemplo n.º 4
0
    def __init__(self, manifests_files: Union[str, List[str]], *args, **kwargs):
        """Parse lists of audio files, durations and transcripts texts.

        Args:
            manifests_files: Either single string file or list of such -
                manifests to yield items from.
            *args: Args to pass to `AudioText` constructor.
            **kwargs: Kwargs to pass to `AudioText` constructor.
        """

        audio_files, durations, texts, offsets = [], [], [], []
        for item in manifest.item_iter(manifests_files):
            audio_files.append(item['audio_file'])
            durations.append(item['duration'])
            texts.append(item['text'])
            offsets.append(item['offset'])

        super().__init__(audio_files, durations, texts, offsets, *args, **kwargs)
    def __init__(self, manifests_files: Union[str, List[str]], *args,
                 **kwargs):
        """Parse lists of audio files, durations and transcripts texts.

        Args:
            manifests_files: Either single string file or list of such -
                manifests to yield items from.
            *args: Args to pass to `SpeechLabel` constructor.
            **kwargs: Kwargs to pass to `SpeechLabel` constructor.
        """
        audio_files, durations, labels = [], [], []

        for item in manifest.item_iter(manifests_files,
                                       parse_func=self.__parse_item):
            audio_files.append(item['audio_file'])
            durations.append(item['duration'])
            labels.append(item['label'])

        super().__init__(audio_files, durations, labels, *args, **kwargs)
Ejemplo n.º 6
0
    def __init__(
        self,
        manifests_files: Union[str, List[str]],
        max_number: Optional[int] = None,
        index_by_file_id: bool = False,
    ):
        """Parse lists of feature files and sequences of labels.

        Args:
            manifests_files: Either single string file or list of such -
                manifests to yield items from.
            max_number:  Maximum number of samples to collect; pass to `FeatureSequenceLabel` constructor.
            index_by_file_id: If True, saves a mapping from filename base (ID) to index in data; pass to `FeatureSequenceLabel` constructor.
        """

        feature_files, seq_labels = [], []
        for item in manifest.item_iter(manifests_files,
                                       parse_func=self._parse_item):
            feature_files.append(item['feature_file'])
            seq_labels.append(item['seq_label'])

        super().__init__(feature_files, seq_labels, max_number,
                         index_by_file_id)