def combine_mixture_and_sources(reference_waveforms, diarization_labels,
                                  speaker_ids, meeting_scale):
    # waveforms has shape (num_sources, num_mics, num_samples).
    speaker_ids = tf.reshape(speaker_ids, (max_num_spk,))
    meeting_scale = meeting_scale[0]
    mixture_waveform = tf.reduce_sum(reference_waveforms, axis=0)
    current_mixture_scale = tf.reduce_max(tf.abs(mixture_waveform))
    # Note that when meetings are chopped, we cannot apply a meeting level
    # scale. Instead, we apply the scale in the chunk level so that each
    # chunk has a maximum scale equal to the meeting_scale. However, we should
    # not apply any gain to an all noise chunk to avoid amplifying the noise,
    # so we try not to scale those chunks by checking the current_mixture_scale
    # value.
    scale_refs = tf.cond(current_mixture_scale > 0.005,
                         lambda: meeting_scale / current_mixture_scale,
                         lambda: 1.0)
    reference_waveforms *= scale_refs
    num_sources = max_num_spk
    if sensor_noise_range[1] > 0.0:
      num_sources += 1
      sensor_noise_gain = tf.random.uniform((), minval=sensor_noise_range[0],
                                            maxval=sensor_noise_range[1])
      sensor_noise = sensor_noise_gain * tf.random.normal(
          (1, num_mics, samples))
      reference_waveforms = tf.concat(
          (sensor_noise, reference_waveforms), axis=0)
    mixture_waveform = tf.reduce_sum(reference_waveforms, axis=0)
    reference_waveforms.set_shape((num_sources, num_mics, samples))
    mixture_waveform.set_shape((num_mics, samples))
    diarization_labels.set_shape((max_num_spk, samples))
    speaker_ids.set_shape((max_num_spk,))
    return {'receiver_audio': mixture_waveform,
            'source_images': reference_waveforms,
            'diarization_labels': diarization_labels,
            'speaker_indices': speaker_ids,
            }