def remove_special_chars(text: str, char_set=0) -> str:
    """Removes special characters from a text.

    :param text: String to be cleaned.
    :param char_set: 0 -> remove all ASCII special chars except for '_' & 'space';
                     1 -> remove invalid chars from file names
    :return: Clean text.
    """
    command_chars = [chr(unicode) for unicode in tuple(range(0, 32)) + (127,)]
    special_chars = ([chr(unicode) for unicode in tuple(range(33, 48)) + tuple(range(58, 65)) + tuple(range(91, 95))
                      + (96,) + tuple(range(123, 127))],
                     ('\\', '/', ':', '*', '?', '"', '<', '>', '|'))
    res = text
    for cm in command_chars:
        res = res.replace(cm, '_')
    for sp in special_chars[char_set]:
        res = res.replace(sp, '_')
    while res.startswith('_'):
        res = res[1:]
    while res.endswith('_'):
        res = res[:-1]
    return res