File size: 921 Bytes
e41ca58
1ffb58d
9f0bf0f
1ffb58d
e41ca58
aff819e
e41ca58
aff819e
 
1ffb58d
 
e41ca58
1ffb58d
 
 
 
 
 
 
 
 
e41ca58
1ffb58d
 
e41ca58
1ffb58d
 
 
 
 
 
 
 
 
e41ca58
9f0bf0f
1ffb58d
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
31
32
33
34
35
36
37
import torch
import scipy
import time
from transformers import set_seed, pipeline

device = 0 if torch.cuda.is_available() else "cpu"


def goai_tts(texte):
    """
    Pour un texte donné, donner le speech en Mooré correspondant
    
    Paramètres
    ---------- 
    texte: str
        Le texte écrit.
        
    Return
    ------
        L'audio synthétisé.
    """
    
    ### assurer la reproductibilité
    set_seed(2024) 
    
    start_time = time.time()

    ### charger le modèle TTS
    model_id = "anyantudre/mms-tts-mos-V1"
    synthesiser = pipeline("text-to-speech", model_id, device=device)  # add device=0 if you want to use a GPU

    ### inférence
    speech = synthesiser(texte)
    wavfile = scipy.io.wavfile.write("finetuned_output.wav", rate=speech["sampling_rate"], data=speech["audio"][0])

    print("Temps écoulé: ", int(time.time() - start_time), " secondes")
    return wavfile