import unicodedata


def preprocess(string, punctuation):
    """Transform the raw txt into a list of word for TTS

    Parameters
    ----------
    string : str
        Raw text file
    punctuation : dict
        Dictionnary with the punctation to pronounce

    Returns
    -------
    list
        List of preprocessed words
    """
    string = string.replace('\n', ' ') # Delete all \n (skip line)

    for key, value in punctuation.items():
        string = string.replace(key, value) # Replace punctuation
    
    string = unicodedata.normalize('NFD', string)\
           .encode('ascii', 'ignore')\
           .decode("utf-8") # Normalize special characters 

    string = string.split(' ') # Split the string into a list

    txt = []
    for word in string:
        if word not in [' ', '']:
            txt.append(word) # Avoid having spaces or blank
    
    return txt