class_docstr: Sample collection writer for writing a CSV data-set and all its referenced WAV samples to a tar file.
class_docstr_tok: ["Sample","collection","writer","for","writing","a","CSV","data-set","and","all","its","referenced","WAV","samples","to","a","tar","file","."]
docstr: Parameters
  ----------
  tar_filename : str
      Path to the tar file to write.
  gz : bool
      If to compress tar file with gzip.
  labeled : bool or None
      If True: Writes labeled samples (util.sample_collections.LabeledSample) only.
      If False: Ignores transcripts (if available) and writes (unlabeled) util.audio.Sample instances.
  include : str[]
      List of files to include into tar root.
  
  Currently only works with local files (not gs:// or hdfs://...)
code: def __init__(
      self, tar_filename, gz=False, labeled=True, include=None
  ):
      """
      Parameters
      ----------
      tar_filename : str
          Path to the tar file to write.
      gz : bool
          If to compress tar file with gzip.
      labeled : bool or None
          If True: Writes labeled samples (util.sample_collections.LabeledSample) only.
          If False: Ignores transcripts (if available) and writes (unlabeled) util.audio.Sample instances.
      include : str[]
          List of files to include into tar root.
  
      Currently only works with local files (not gs:// or hdfs://...)
      """
      self.tar = tarfile.open(tar_filename, "w:gz" if gz else "w")
      samples_dir = tarfile.TarInfo("samples")
      samples_dir.type = tarfile.DIRTYPE
      self.tar.addfile(samples_dir)
      if include:
          for include_path in include:
              self.tar.add(
                  include_path,
                  recursive=False,
                  arcname=Path(include_path).name,
              )
      fieldnames = ["wav_filename", "wav_filesize"]
      self.labeled = labeled
      if labeled:
          fieldnames.append("transcript")
      self.csv_file = io.StringIO()
      self.csv_writer = csv.DictWriter(
          self.csv_file, fieldnames=fieldnames
      )
      self.csv_writer.writeheader()
      self.counter = 0
  
imports: import os
  import io
  import csv
  import json
  import tarfile
  from pathlib import Path
  from functools import partial
  from .helpers import KILOBYTE, MEGABYTE, GIGABYTE, Interleaved, LenMap
  from .audio import Sample, AUDIO_TYPE_PCM, AUDIO_TYPE_OPUS, SERIALIZABLE_AUDIO_TYPES, get_loadable_audio_type_from_extension, write_wav
  from .io import open_remote, is_remote_path
label_desc: Use image node_id 1 to create a new TarWriter object  with example: obj = TarWriter(tar_filename, gz, labeled, include)