code: def collect_samples(base_dir, language):
      roots = []
      for root, _, files in os.walk(base_dir):
          if ALIGNED_NAME in files and WAV_NAME in files:
              roots.append(root)
      samples = []
      reasons = Counter()
  
      def add_sample(
          p_wav_path,
          p_article,
          p_speaker,
          p_start,
          p_end,
          p_text,
          p_reason="complete",
      ):
          if (
              p_start is not None
              and p_end is not None
              and p_text is not None
          ):
              duration = p_end - p_start
              text, filter_reason = label_filter(p_text, language)
              skip = False
              if filter_reason is not None:
                  skip = True
                  p_reason = filter_reason
              elif (
                  CLI_ARGS.exclude_unknown_speakers
                  and p_speaker == UNKNOWN
              ):
                  skip = True
                  p_reason = "unknown speaker"
              elif (
                  CLI_ARGS.exclude_unknown_articles
                  and p_article == UNKNOWN
              ):
                  skip = True
                  p_reason = "unknown article"
              elif (
                  duration > CLI_ARGS.max_duration > 0
                  and CLI_ARGS.ignore_too_long
              ):
                  skip = True
                  p_reason = "exceeded duration"
              elif int(duration / 30) < len(text):
                  skip = True
                  p_reason = "too short to decode"
              elif duration / len(text) < 10:
                  skip = True
                  p_reason = "length duration ratio"
              if skip:
                  reasons[p_reason] += 1
              else:
                  samples.append(
                      Sample(
                          p_wav_path,
                          p_start,
                          p_end,
                          text,
                          p_article,
                          p_speaker,
                      )
                  )
          elif p_start is None or p_end is None:
              reasons["missing timestamps"] += 1
          else:
              reasons["missing text"] += 1
  
      print("Collecting samples...")
      bar = progressbar.ProgressBar(
          max_value=len(roots), widgets=SIMPLE_BAR
      )
      for root in bar(roots):
          wav_path = os.path.join(root, WAV_NAME)
          aligned = ET.parse(os.path.join(root, ALIGNED_NAME))
          article = UNKNOWN
          speaker = UNKNOWN
          for prop in aligned.iter("prop"):
              attributes = prop.attrib
              if "key" in attributes and "value" in attributes:
                  if attributes["key"] == "DC.identifier":
                      article = attributes["value"]
                  elif attributes["key"] == "reader.name":
                      speaker = attributes["value"]
          for sentence in aligned.iter("s"):
              if ignored(sentence):
                  continue
              split = False
              tokens = list(map(read_token, sentence.findall("t")))
              sample_start, sample_end, token_texts, sample_texts = (
                  None,
                  None,
                  [],
                  [],
              )
              for token_start, token_end, token_text in tokens:
                  if CLI_ARGS.exclude_numbers and any(
                      c.isdigit() for c in token_text
                  ):
                      add_sample(
                          wav_path,
                          article,
                          speaker,
                          sample_start,
                          sample_end,
                          " ".join(sample_texts),
                          p_reason="has numbers",
                      )
                      (
                          sample_start,
                          sample_end,
                          token_texts,
                          sample_texts,
                      ) = (
                          None,
                          None,
                          [],
                          [],
                      )
                      continue
                  if sample_start is None:
                      sample_start = token_start
                  if sample_start is None:
                      continue
                  token_texts.append(token_text)
                  if token_end is not None:
                      if (
                          token_start != sample_start
                          and token_end - sample_start
                          > CLI_ARGS.max_duration
                          > 0
                      ):
                          add_sample(
                              wav_path,
                              article,
                              speaker,
                              sample_start,
                              sample_end,
                              " ".join(sample_texts),
                              p_reason="split",
                          )
                          sample_start = sample_end
                          sample_texts = []
                          split = True
                      sample_end = token_end
                      sample_texts.extend(token_texts)
                      token_texts = []
              add_sample(
                  wav_path,
                  article,
                  speaker,
                  sample_start,
                  sample_end,
                  " ".join(sample_texts),
                  p_reason="split" if split else "complete",
              )
      print("Skipped samples:")
      for reason, n in reasons.most_common():
          print(" - {}: {}".format(reason, n))
      return samples
  
imports: import argparse
  import csv
  import os
  import random
  import re
  import shutil
  import sys
  import tarfile
  import unicodedata
  import wave
  import xml.etree.ElementTree
  from collections import Counter
  from glob import glob
  from multiprocessing.pool import ThreadPool
  import progressbar
  import sox
  from deepspeech_training.util.downloader import SIMPLE_BAR, maybe_download
  from deepspeech_training.util.importers import validate_label_eng
  from ds_ctcdecoder import Alphabet
label_desc: Use image node_id 11 for calling a global function with example usage: collect_samples(base_dir, language) and returns: samples