anyantudre's picture
Update goai_tts.py
c319df3 verified
raw
history blame
869 Bytes
import torch
import scipy
import time
from transformers import set_seed, pipeline
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