code: def file_writer_helper(
      wspecifier: str,
      filetype: str = "mat",
      write_num_frames: str = None,
      compress: bool = False,
      compression_method: int = 2,
      pcm_format: str = "wav",
  ):
      """Write matrices in kaldi style
  
      Args:
          wspecifier: e.g. ark,scp:out.ark,out.scp
          filetype: "mat" is kaldi-martix, "hdf5": HDF5
          write_num_frames: e.g. 'ark,t:num_frames.txt'
          compress: Compress or not
          compression_method: Specify compression level
  
      Write in kaldi-matrix-ark with "kaldi-scp" file:
  
      >>> with file_writer_helper('ark,scp:out.ark,out.scp') as f:
      >>>     f['uttid'] = array
  
      This "scp" has the following format:
  
          uttidA out.ark:1234
          uttidB out.ark:2222
  
      where, 1234 and 2222 points the strating byte address of the matrix.
      (For detail, see official documentation of Kaldi)
  
      Write in HDF5 with "scp" file:
  
      >>> with file_writer_helper('ark,scp:out.h5,out.scp', 'hdf5') as f:
      >>>     f['uttid'] = array
  
      This "scp" file is created as:
  
          uttidA out.h5:uttidA
          uttidB out.h5:uttidB
  
      HDF5 can be, unlike "kaldi-ark", accessed to any keys,
      so originally "scp" is not required for random-reading.
      Nevertheless we create "scp" for HDF5 because it is useful
      for some use-case. e.g. Concatenation, Splitting.
  
      """
      if filetype == "mat":
          return KaldiWriter(
              wspecifier,
              write_num_frames=write_num_frames,
              compress=compress,
              compression_method=compression_method,
          )
      elif filetype == "hdf5":
          return HDF5Writer(
              wspecifier,
              write_num_frames=write_num_frames,
              compress=compress,
          )
      elif filetype == "sound.hdf5":
          return SoundHDF5Writer(
              wspecifier,
              write_num_frames=write_num_frames,
              pcm_format=pcm_format,
          )
      elif filetype == "sound":
          return SoundWriter(
              wspecifier,
              write_num_frames=write_num_frames,
              pcm_format=pcm_format,
          )
      else:
          raise NotImplementedError(f"filetype={filetype}")
  
imports: from pathlib import Path
  from typing import Dict
  import h5py
  import kaldiio
  import numpy
  import soundfile
  from espnet.utils.cli_utils import assert_scipy_wav_style
  from espnet.utils.io_utils import SoundHDF5File
label_desc: Use image node_id 1 for calling a global function with example usage: file_writer_helper(wspecifier, filetype, write_num_frames, compress, compression_method, pcm_format) and returns: KaldiWriter, HDF5Writer, SoundHDF5Writer, SoundWriter