code: def write_manifest(
      out_dir,
      files,
      prefix,
      manifest_name,
      start=0.0,
      end=None,
      duration_stride=1.0,
      duration_max=None,
      duration_limit=100.0,
      filter_long=False,
  ):
      """
      Given a list of files, segment each file and write them to manifest with restrictions.
      Args:
          out_dir: directory of generated manifest
          files: list of files to be processed
          prefix: label of samples
          manifest_name: name of generated manifest
          start: beginning of audio of generating segment
          end: end of audio of generating segment
          duration_stride: stride for segmenting audio samples
          duration_max: duration for each segment
          duration_limit: duration threshold for filtering out long audio samples
          filter_long: boolean to determine whether to filter out long audio samples
      Returns:
      """
      seg_num = 0
      skip_num = 0
      if duration_max is None:
          duration_max = 1e9
  
      if not os.path.exists(out_dir):
          logging.info(
              f"Outdir {out_dir} does not exist. Creat directory."
          )
          os.mkdir(out_dir)
  
      output_path = os.path.join(out_dir, manifest_name + ".json")
      with open(output_path, "w") as fout:
          for file in files:
              label = prefix
  
              try:
                  x, _sr = librosa.load(file, sr=sr)
                  duration = librosa.get_duration(y=x, sr=sr)
  
              except Exception:
                  continue
  
              if filter_long and duration > duration_limit:
                  skip_num += 1
                  continue
  
              offsets = []
              durations = []
  
              if duration > duration_max:
                  current_offset = start
  
                  while current_offset < duration:
                      if end is not None and current_offset > end:
                          break
  
                      difference = duration - current_offset
  
                      if difference < duration_max:
                          break
  
                      offsets.append(current_offset)
                      durations.append(duration_max)
  
                      current_offset += duration_stride
  
              else:
                  # Duration is not long enough! Skip
                  skip_num += 1
  
              for duration, offset in zip(durations, offsets):
                  metadata = {
                      "audio_filepath": file,
                      "duration": duration,
                      "label": label,
                      "text": "_",  # for compatibility with ASRAudioText
                      "offset": offset,
                  }
                  json.dump(metadata, fout)
                  fout.write("\n")
                  fout.flush()
                  seg_num += 1
      return skip_num, seg_num, output_path
  
imports: import argparse
  import glob
  import json
  import logging
  import os
  import tarfile
  import urllib.request
  import librosa
  import numpy
  import soundfile
  from sklearn.model_selection import train_test_split
label_desc: Use image node_id 6 for calling a global function with example usage: write_manifest(out_dir, files, prefix, manifest_name, start, end, duration_stride, duration_max, duration_limit, filter_long) and returns: skip_num,  seg_num,  output_path