code: def create_tar_datasets(
      min_duration: float, max_duration: float, target_dir: str
  ):
      builder = ASRTarredDatasetBuilder()
  
      shard_manifests = False if args.no_shard_manifests else True
  
      if args.write_metadata:
          metadata = ASRTarredDatasetMetadata()
          dataset_cfg = ASRTarredDatasetConfig(
              num_shards=args.num_shards,
              shuffle=args.shuffle,
              max_duration=max_duration,
              min_duration=min_duration,
              shuffle_seed=args.shuffle_seed,
              sort_in_shards=args.sort_in_shards,
              shard_manifests=shard_manifests,
              keep_files_together=args.keep_files_together,
              force_codec=args.force_codec,
          )
          metadata.dataset_config = dataset_cfg
  
          output_path = os.path.join(
              target_dir, "default_metadata.yaml"
          )
          OmegaConf.save(metadata, output_path, resolve=True)
          print(f"Default metadata written to {output_path}")
          exit(0)
  
      if (
          args.concat_manifest_paths is None
          or len(args.concat_manifest_paths) == 0
      ):
          print("Creating new tarred dataset ...")
  
          # Create a tarred dataset from scratch
          config = ASRTarredDatasetConfig(
              num_shards=args.num_shards,
              shuffle=args.shuffle,
              max_duration=max_duration,
              min_duration=min_duration,
              shuffle_seed=args.shuffle_seed,
              sort_in_shards=args.sort_in_shards,
              shard_manifests=shard_manifests,
              keep_files_together=args.keep_files_together,
              force_codec=args.force_codec,
          )
          builder.configure(config)
          builder.create_new_dataset(
              manifest_path=args.manifest_path,
              target_dir=target_dir,
              num_workers=args.workers,
          )
  
      else:
          if args.buckets_num > 1:
              raise ValueError(
                  "Concatenation feature does not support buckets_num > 1."
              )
          print("Concatenating multiple tarred datasets ...")
  
          # Implicitly update config from base details
          if args.metadata_path is not None:
              metadata = ASRTarredDatasetMetadata.from_file(
                  args.metadata_path
              )
          else:
              raise ValueError(
                  "`metadata` yaml file path must be provided!"
              )
  
          # Preserve history
          history = []
          builder.setup_history(OmegaConf.structured(metadata), history)
          metadata.history = history
  
          # Add command line overrides (everything other than num_shards)
          metadata.dataset_config.max_duration = max_duration
          metadata.dataset_config.min_duration = min_duration
          metadata.dataset_config.shuffle = args.shuffle
          metadata.dataset_config.shuffle_seed = args.shuffle_seed
          metadata.dataset_config.sort_in_shards = args.sort_in_shards
          metadata.dataset_config.shard_manifests = shard_manifests
  
          builder.configure(metadata.dataset_config)
  
          # Concatenate a tarred dataset onto a previous one
          builder.create_concatenated_dataset(
              base_manifest_path=args.manifest_path,
              manifest_paths=args.concat_manifest_paths,
              metadata=metadata,
              target_dir=target_dir,
              num_workers=args.workers,
          )
  
      if (
          DALI_INDEX_SCRIPT_AVAILABLE
          and dali_index.INDEX_CREATOR_AVAILABLE
      ):
          print("Constructing DALI Tarfile Index - ", target_dir)
          index_config = dali_index.DALITarredIndexConfig(
              tar_dir=target_dir, workers=args.workers
          )
          dali_index.main(index_config)
  
imports: import argparse
  import copy
  import json
  import os
  import random
  import tarfile
  from collections import defaultdict
  from dataclasses import dataclass, field
  from datetime import datetime
  from io import BytesIO
  from typing import Any, List, Optional
  import numpy
  import soundfile
  from joblib import Parallel, delayed
  from omegaconf import DictConfig, OmegaConf, open_dict
label_desc: Use image node_id 2 for calling a global function with example usage: create_tar_datasets(min_duration, max_duration, target_dir) without return types