code: def create_example(example_id, ns, wav_data, velocity_range=None):
      """Creates a tf.train.Example proto for training or testing."""
      if velocity_range is None:
          velocity_range = velocity_range_from_sequence(ns)
  
      # Ensure that all sequences for training and evaluation have gone through
      # sustain processing.
      sus_ns = sequences_lib.apply_sustain_control_changes(ns)
  
      example = tf.train.Example(
          features=tf.train.Features(
              feature={
                  "id": tf.train.Feature(
                      bytes_list=tf.train.BytesList(
                          value=[example_id.encode("utf-8")]
                      )
                  ),
                  "sequence": tf.train.Feature(
                      bytes_list=tf.train.BytesList(
                          value=[sus_ns.SerializeToString()]
                      )
                  ),
                  "audio": tf.train.Feature(
                      bytes_list=tf.train.BytesList(value=[wav_data])
                  ),
                  "velocity_range": tf.train.Feature(
                      bytes_list=tf.train.BytesList(
                          value=[velocity_range.SerializeToString()]
                      )
                  ),
              }
          )
      )
      return example
  
file_path: magenta/magenta/models/onsets_frames_transcription/audio_label_data_utils.py
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  import bisect
  import math
  import librosa
  from note_seq import audio_io
  from note_seq import constants
  from note_seq import sequences_lib
  from note_seq.protobuf import music_pb2
  import numpy
  import tensorflow.compat.v1
label_desc: Use image node_id 5 for calling a global function with example usage: create_example(example_id, ns, wav_data, velocity_range) and returns: example