class_docstr: Meta data for a kaldi corpus directory. 
class_docstr_tok: ["Meta","data","for","a","kaldi","corpus","directory","."]
docstr: Write contents to dir in Kaldi style. 
docstr_tok: ["Write","contents","to","dir","in","Kaldi","style","."]
code: def dump(self, data_path, overwrite=False):
      """Write contents to dir in Kaldi style."""
  
      # Don't overwrite existing data repo.
      logging.info("Dumping to data dir %s ..." % (data_path))
      if os.path.isdir(data_path) and not overwrite:
          logging.warning(
              "Dir %s exists and overwrite = False, skip." % (data_path)
          )
          return
      os.makedirs(data_path, mode=0o755, exist_ok=True)
  
      # Dump data in sorted order.
      sorted_utt_keys = sorted(self.utts.keys())
      for file_name, prop_name in self.files_to_load:
          empty = True
          for utt_key in sorted_utt_keys:
              if self.utts[utt_key][prop_name]:
                  empty = False
                  break
          if not empty:
              file_path = os.path.join(data_path, file_name)
              logging.info(
                  "Dumping prop %s to file %s ..."
                  % (prop_name, file_name)
              )
              with open(file_path, "w") as fp_out:
                  for utt_key in sorted_utt_keys:
                      if self.utts[utt_key][prop_name]:
                          fp_out.write(
                              "%s %s\n"
                              % (utt_key, self.utts[utt_key][prop_name])
                          )
  
      # Generate speaker -> various data.
      spk_files_to_dump = [
          ("spk2id", {s[0]: s[1].id for s in self.spks.items()}),
          ("spk2utt", {s[0]: s[1].utts for s in self.spks.items()}),
          (
              "spk2numutt",
              {s[0]: s[1].numutt for s in self.spks.items()},
          ),
      ]
      sorted_spks = sorted(self.spks.keys())
      for file_name, dict_inst in spk_files_to_dump:
          # Maybe we can wrap this into a function?
          logging.info("Dumping file %s ..." % (file_name))
          with open(os.path.join(data_path, file_name), "w") as fp_out:
              for spk in sorted_spks:
                  value = dict_inst[spk]
                  if hasattr(value, "__iter__"):
                      fp_out.write(
                          "%s %s\n" % (spk, " ".join(sorted(value)))
                      )
                  else:
                      fp_out.write("%s %s\n" % (spk, value))
  
file_path: delta/delta/utils/kaldi/kaldi_dir.py
imports: import os
  from collections import defaultdict
  from absl import logging
label_desc: Use image node_id 8 for calling the KaldiMetaData obj's underlying member method code with example usage: obj.dump(data_path, overwrite) without return types