code: def build_map_dataset_to_nemo_func(
      cfg: HFDatasetConversionConfig, basedir
  ):
      """
      Helper method to run in batch mode over a mapped Dataset.
  
      Creates a function that can be passed to Dataset.map() containing the config and basedir.
      Useful to map a HF dataset to NeMo compatible format in an efficient way for offline processing.
  
      Returns:
          A function pointer which can be used for Dataset.map()
      """
  
      def map_dataset_to_nemo(batch):
          # Write audio file to correct path
          if cfg.streaming:
              batch["audio_filepath"] = (
                  batch["audio"]["path"]
                  .split("::")[0]
                  .replace("zip://", "")
              )
          else:
              segments = infer_dataset_segments(batch)
              audio_filepath = os.path.join(*segments)
              batch["audio_filepath"] = audio_filepath
  
          batch["audio_filepath"] = os.path.abspath(
              os.path.join(basedir, batch["audio_filepath"])
          )
          audio_filepath = batch["audio_filepath"]
          audio_filepath = prepare_audio_filepath(audio_filepath)
          batch[
              "audio_filepath"
          ] = audio_filepath  # update filepath with prepared path
  
          soundfile.write(
              audio_filepath,
              batch["audio"]["array"],
              samplerate=cfg.sampling_rate,
              format="wav",
          )
  
          batch["duration"] = librosa.get_duration(
              y=batch["audio"]["array"],
              sr=batch["audio"]["sampling_rate"],
          )
          return batch
  
      return map_dataset_to_nemo
  
imports: import json
  import os
  import traceback
  from dataclasses import dataclass, is_dataclass
  from typing import Optional
  import hydra
  import librosa
  import soundfile
  import tqdm
  from datasets import Audio, Dataset, IterableDataset, load_dataset
  from hydra.conf import HydraConf, RunDir
  from hydra.core.config_store import ConfigStore
  from omegaconf import OmegaConf
label_desc: Use image node_id 4 for calling a global function with example usage: build_map_dataset_to_nemo_func(cfg, basedir) and returns: map_dataset_to_nemo, batch