(mixid_exs, sample_rate, load_audio_with_librosa)
return examples[0]
Mix several Examples together to create a new example.
Mix several Examples together to create a new example.
Mix several Examples together to create a new example .
def mix_examples(mixid_exs, sample_rate, load_audio_with_librosa):
  """Mix several Examples together to create a new example."""
  mixid, exs = mixid_exs
  del mixid

  example_samples = []
  example_sequences = []

  for ex_str in exs:
    ex = tf.train.Example.FromString(ex_str)
    wav_data = ex.features.feature['audio'].bytes_list.value[0]
    if load_audio_with_librosa:
      samples = audio_io.wav_data_to_samples_librosa(wav_data, sample_rate)
    else:
      samples = audio_io.wav_data_to_samples(wav_data, sample_rate)
    example_samples.append(samples)
    ns = music_pb2.NoteSequence.FromString(
        ex.features.feature['sequence'].bytes_list.value[0])
    example_sequences.append(ns)

  mixed_samples, mixed_sequence = audio_label_data_utils.mix_sequences(
      individual_samples=example_samples, sample_rate=sample_rate,
      individual_sequences=example_sequences)

  mixed_wav_data = audio_io.samples_to_wav_data(mixed_samples, sample_rate)

  mixed_id = '::'.join(['mixed'] + [ns.id for ns in example_sequences])
  mixed_sequence.id = mixed_id
  mixed_filename = '::'.join(
      ['mixed'] + [ns.filename for ns in example_sequences])
  mixed_sequence.filename = mixed_filename

  examples = list(audio_label_data_utils.process_record(
      mixed_wav_data,
      mixed_sequence,
      mixed_id,
      min_length=0,
      max_length=-1,
      sample_rate=sample_rate))
  assert len(examples) == 1
  return examples[0]
def mix_examples ( mixid_exs , sample_rate , load_audio_with_librosa ) : mixid , exs = mixid_exs del mixid example_samples = [ ] example_sequences = [ ] for ex_str in exs : ex = tf . train . Example . FromString ( ex_str ) wav_data = ex . features . feature [ 'audio' ] . bytes_list . value [ 0 ] if load_audio_with_librosa : samples = audio_io . wav_data_to_samples_librosa ( wav_data , sample_rate ) else : samples = audio_io . wav_data_to_samples ( wav_data , sample_rate ) example_samples . append ( samples ) ns = music_pb2 . NoteSequence . FromString ( ex . features . feature [ 'sequence' ] . bytes_list . value [ 0 ] ) example_sequences . append ( ns ) mixed_samples , mixed_sequence = audio_label_data_utils . mix_sequences ( individual_samples = example_samples , sample_rate = sample_rate , individual_sequences = example_sequences ) mixed_wav_data = audio_io . samples_to_wav_data ( mixed_samples , sample_rate ) mixed_id = '::' . join ( [ 'mixed' ] + [ ns . id for ns in example_sequences ] ) mixed_sequence . id = mixed_id mixed_filename = '::' . join ( [ 'mixed' ] + [ ns . filename for ns in example_sequences ] ) mixed_sequence . filename = mixed_filename examples = list ( audio_label_data_utils . process_record ( mixed_wav_data , mixed_sequence , mixed_id , min_length = 0 , max_length = - 1 , sample_rate = sample_rate ) ) assert len ( examples ) == 1 return examples [ 0 ]