File size: 742 Bytes
4300fed
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
from .cleaner import french_cleaners
from .gruut_wrapper import Gruut


def remove_consecutive_t(input_str):
    result = []
    count = 0

    for char in input_str:
        if char == 't':
            count += 1
        else:
            if count < 3:  
                result.extend(['t'] * count)
            count = 0
            result.append(char)

    if count < 3:
        result.extend(['t'] * count)

    return ''.join(result)

def fr2ipa(text):
    e = Gruut(language="fr-fr", keep_puncs=True, keep_stress=True, use_espeak_phonemes=True)
    # text = french_cleaners(text)
    phonemes = e.phonemize(text, separator="")
    # print(phonemes)
    phonemes = remove_consecutive_t(phonemes)
    # print(phonemes)
    return phonemes