(input_example, min_length, max_length, sample_rate,
              debug_output_directory, split_example, load_audio_with_librosa)
Splits wav and midi files for the dataset.
Splits wav and midi files for the dataset.
Splits wav and midi files for the dataset .
def split_wav(input_example, min_length, max_length, sample_rate,
              debug_output_directory, split_example, load_audio_with_librosa):
  """Splits wav and midi files for the dataset."""
  tf.logging.info('Splitting %s',
                  input_example.features.feature['id'].bytes_list.value[0])

  wav_data = input_example.features.feature['audio'].bytes_list.value[0]

  ns = music_pb2.NoteSequence.FromString(
      input_example.features.feature['sequence'].bytes_list.value[0])

  Metrics.counter('split_wav', 'read_midi_wav_to_split').inc()

  if not split_example:
    split_examples = audio_label_data_utils.process_record(
        wav_data,
        ns,
        ns.id,
        min_length=0,
        max_length=-1,
        sample_rate=sample_rate,
        allow_empty_notesequence=True,
        load_audio_with_librosa=load_audio_with_librosa)

    for example in split_examples:
      Metrics.counter('split_wav', 'full_example').inc()
      yield example
  else:
    try:
      split_examples = audio_label_data_utils.process_record(
          wav_data,
          ns,
          ns.id,
          min_length=min_length,
          max_length=max_length,
          sample_rate=sample_rate,
          load_audio_with_librosa=load_audio_with_librosa)

      for example in split_examples:
        Metrics.counter('split_wav', 'split_example').inc()
        yield example
    except AssertionError:
      output_file = 'badexample-' + hashlib.md5(
          ns.id.encode('utf-8')).hexdigest() + '.proto'
      output_path = os.path.join(debug_output_directory, output_file)
      tf.logging.error('Exception processing %s. Writing file to %s', ns.id,
                       output_path)
      with tf.gfile.Open(output_path, 'w') as f:
        f.write(input_example.SerializeToString())
      raise
def split_wav ( input_example , min_length , max_length , sample_rate , debug_output_directory , split_example , load_audio_with_librosa ) : tf . logging . info ( 'Splitting %s' , input_example . features . feature [ 'id' ] . bytes_list . value [ 0 ] ) wav_data = input_example . features . feature [ 'audio' ] . bytes_list . value [ 0 ] ns = music_pb2 . NoteSequence . FromString ( input_example . features . feature [ 'sequence' ] . bytes_list . value [ 0 ] ) Metrics . counter ( 'split_wav' , 'read_midi_wav_to_split' ) . inc ( ) if not split_example : split_examples = audio_label_data_utils . process_record ( wav_data , ns , ns . id , min_length = 0 , max_length = - 1 , sample_rate = sample_rate , allow_empty_notesequence = True , load_audio_with_librosa = load_audio_with_librosa ) for example in split_examples : Metrics . counter ( 'split_wav' , 'full_example' ) . inc ( ) yield example else : try : split_examples = audio_label_data_utils . process_record ( wav_data , ns , ns . id , min_length = min_length , max_length = max_length , sample_rate = sample_rate , load_audio_with_librosa = load_audio_with_librosa ) for example in split_examples : Metrics . counter ( 'split_wav' , 'split_example' ) . inc ( ) yield example except AssertionError : output_file = 'badexample-' + hashlib . md5 ( ns . id . encode ( 'utf-8' ) ) . hexdigest ( ) + '.proto' output_path = os . path . join ( debug_output_directory , output_file ) tf . logging . error ( 'Exception processing %s. Writing file to %s' , ns . id , output_path ) with tf . gfile . Open ( output_path , 'w' ) as f : f . write ( input_example . SerializeToString ( ) ) raise