def paths_and_labels_to_dataset(
    file_paths,
    labels,
    label_mode,
    num_classes,
    sampling_rate,
    output_sequence_length,
    ragged,
    shuffle=False,
    shuffle_buffer_size=None,
    seed=None,
):
    """Constructs a fixed-size dataset of audio and labels."""
    path_ds = tf.data.Dataset.from_tensor_slices(file_paths)
    if label_mode:
        label_ds = dataset_utils.labels_to_dataset(
            labels, label_mode, num_classes
        )
        ds = tf.data.Dataset.zip((path_ds, label_ds))
    else:
        ds = path_ds

    if shuffle:
        ds = ds.shuffle(buffer_size=shuffle_buffer_size or 1024, seed=seed)

    if label_mode:
        ds = ds.map(
            lambda x, y: (
                read_and_decode_audio(x, sampling_rate, output_sequence_length),
                y,
            ),
            num_parallel_calls=tf.data.AUTOTUNE,
        )

        if ragged:
            ds = ds.map(
                lambda x, y: (tf.RaggedTensor.from_tensor(x), y),
                num_parallel_calls=tf.data.AUTOTUNE,
            )

    else:
        ds = ds.map(
            lambda x: read_and_decode_audio(
                x, sampling_rate, output_sequence_length
            ),
            num_parallel_calls=tf.data.AUTOTUNE,
        )

        if ragged:
            ds = ds.map(
                lambda x: tf.RaggedTensor.from_tensor(x),
                num_parallel_calls=tf.data.AUTOTUNE,
            )

    return ds
Constructs a fixed-size dataset of audio and labels.
keras/src/utils/audio_dataset_utils.py