code: def prepare_tfrecord(
      input_audio_paths,
      output_tfrecord_path,
      num_shards=None,
      sample_rate=16000,
      frame_rate=250,
      example_secs=4,
      hop_secs=1,
      eval_split_fraction=0.0,
      chunk_secs=20.0,
      center=False,
      viterbi=True,
      pipeline_options="",
  ):
      """Prepares a TFRecord for use in training, evaluation, and prediction.
  
      Args:
        input_audio_paths: An iterable of paths to audio files to include in
          TFRecord.
        output_tfrecord_path: The prefix path to the output TFRecord. Shard numbers
          will be added to actual path(s).
        num_shards: The number of shards to use for the TFRecord. If None, this
          number will be determined automatically.
        sample_rate: The sample rate to use for the audio.
        frame_rate: The frame rate to use for f0 and loudness features. If set to
          None, these features will not be computed.
        example_secs: The size of the sliding window (in seconds) to use to split
          the audio and features. If 0, they will not be split.
        hop_secs: The number of seconds to hop when computing the sliding windows.
        eval_split_fraction: Fraction of the dataset to reserve for eval split. If
          set to 0, no eval split is created.
        chunk_secs: Chunk size in seconds used to split the input audio
          files. This is used to split large audio files into manageable chunks for
          better parallelization and to enable non-overlapping train/eval splits.
        center: Provide zero-padding to audio so that frame timestamps will be
          centered.
        viterbi: Use viterbi decoding of pitch.
        pipeline_options: An iterable of command line arguments to be used as
          options for the Beam Pipeline.
      """
  
      def postprocess_pipeline(examples, output_path, stage_name=""):
          """After chunking, features, and train-eval split, create TFExamples."""
          if stage_name:
              stage_name = f"_{stage_name}"
  
          if example_secs:
              examples |= f"split_examples{stage_name}" >> beam.FlatMap(
                  _split_example,
                  sample_rate=sample_rate,
                  frame_rate=frame_rate,
                  example_secs=example_secs,
                  hop_secs=hop_secs,
                  center=center,
              )
          _ = (
              examples
              | f"reshuffle{stage_name}" >> beam.Reshuffle()
              | f"make_tfexample{stage_name}"
              >> beam.Map(_float_dict_to_tfexample)
              | f"write{stage_name}"
              >> beam.io.tfrecordio.WriteToTFRecord(
                  output_path,
                  num_shards=num_shards,
                  coder=beam.coders.ProtoCoder(tf.train.Example),
              )
          )
  
      # Start the pipeline.
      pipeline_options = beam.options.pipeline_options.PipelineOptions(
          pipeline_options
      )
      with beam.Pipeline(options=pipeline_options) as pipeline:
          examples = (
              pipeline
              | beam.Create(input_audio_paths)
              | beam.Map(_load_audio, sample_rate)
          )
  
          # Split into chunks for train/eval split and better parallelism.
          if chunk_secs:
              examples |= beam.FlatMap(
                  _chunk_audio,
                  sample_rate=sample_rate,
                  chunk_secs=chunk_secs,
              )
  
          # Add features.
          if frame_rate:
              examples = (
                  examples
                  | beam.Map(
                      _add_f0_estimate,
                      frame_rate=frame_rate,
                      center=center,
                      viterbi=viterbi,
                  )
                  | beam.Map(
                      _add_loudness,
                      frame_rate=frame_rate,
                      n_fft=512,
                      center=center,
                  )
              )
  
          # Create train/eval split.
          if eval_split_fraction:
              examples |= beam.Map(_add_key)
              keys = examples | beam.Keys()
              splits = examples | beam.Partition(
                  _eval_split_partition_fn,
                  2,
                  eval_split_fraction,
                  beam.pvalue.AsList(keys),
              )
  
              # Remove ids.
              eval_split = splits[0] | "remove_id_eval" >> beam.Map(
                  lambda x: x[1]
              )
              train_split = splits[1] | "remove_id_train" >> beam.Map(
                  lambda x: x[1]
              )
  
              postprocess_pipeline(
                  eval_split, f"{output_tfrecord_path}-eval", "eval"
              )
              postprocess_pipeline(
                  train_split, f"{output_tfrecord_path}-train", "train"
              )
          else:
              postprocess_pipeline(examples, output_tfrecord_path)
  
file_path: ddsp/ddsp/training/data_preparation/prepare_tfrecord_lib.py
imports: from absl import logging
  import apache_beam
  from ddsp import spectral_ops
  import numpy
  import pydub
  import tensorflow.compat.v2
label_desc: Use image node_id 10 for calling a global function with example usage: prepare_tfrecord(input_audio_paths, output_tfrecord_path, num_shards, sample_rate, frame_rate, example_secs, hop_secs, eval_split_fraction, chunk_secs, center, viterbi, pipeline_options) without return types