from typing import Sequence
import math


def split_train_test_validate(
    filenames: Sequence, train: int = 80, test: int = 10, validate: int = 10
) -> tuple[Sequence, Sequence, Sequence]:
    """
    Split the audio filenames into train, test, and validate segments.

    :param filenames: filenames corresponding to audio training data files.
    :param train: percentage of files to use for the train dataset.
    :param test: percentage of files to use for the test dataset.
    :param validate: percentage of files to use for the validation dataset.
    """
    if train + test + validate != 100:
        raise ValueError("train + test + validate percentages != 100%")

    total = len(filenames)
    traind = math.floor((train / 100.0) * total)
    vald = math.floor((validate / 100.0) * total)

    return (
        filenames[:traind],
        filenames[traind + vald :],
        filenames[traind : traind + vald],
    )