Spaces:
Runtime error
Runtime error
Update text_to_speech.py
Browse files- text_to_speech.py +29 -32
text_to_speech.py
CHANGED
@@ -1,40 +1,37 @@
|
|
1 |
import time
|
2 |
import torch
|
3 |
-
|
4 |
-
from transformers import
|
5 |
|
6 |
-
def synthesize_facebook(s:str, iso3:str) -> str:
|
7 |
-
'''
|
8 |
-
For given text, speak it.
|
9 |
-
|
10 |
-
Parameters
|
11 |
-
----------
|
12 |
-
s: str
|
13 |
-
The written text.
|
14 |
-
is03:str
|
15 |
-
The ISO-3 code of the text's language.
|
16 |
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
The synthesized audio.
|
21 |
-
'''
|
22 |
-
|
23 |
-
# Ensure replicability
|
24 |
-
set_seed(555)
|
25 |
-
start_time = time.time()
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
-
|
34 |
-
|
35 |
-
outputs = model(**inputs)
|
36 |
|
37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
38 |
|
39 |
-
print("
|
40 |
-
return
|
|
|
1 |
import time
|
2 |
import torch
|
3 |
+
import scipy
|
4 |
+
from transformers import set_seed, pipeline
|
5 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
+
def goai_tts(texte, device):
|
8 |
+
"""
|
9 |
+
Pour un texte donné, donner le speech en Mooré correspondant
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
+
Paramètres
|
12 |
+
----------
|
13 |
+
texte: str
|
14 |
+
Le texte écrit.
|
15 |
+
device: str
|
16 |
+
GPU ou CPU
|
17 |
+
|
18 |
+
Return
|
19 |
+
------
|
20 |
+
L'audio synthétisé.
|
21 |
+
"""
|
22 |
|
23 |
+
### assurer la reproductibilité
|
24 |
+
set_seed(2024)
|
|
|
25 |
|
26 |
+
start_time = time.time()
|
27 |
+
|
28 |
+
### charger le modèle TTS
|
29 |
+
model_id = "anyantudre/mms-tts-mos-V1"
|
30 |
+
synthesiser = pipeline("text-to-speech", model_id, device=device) # add device=0 if you want to use a GPU
|
31 |
+
|
32 |
+
### inférence
|
33 |
+
speech = synthesiser(texte)
|
34 |
+
wavfile = scipy.io.wavfile.write("finetuned_output.wav", rate=speech["sampling_rate"], data=speech["audio"][0])
|
35 |
|
36 |
+
print("Temps écoulé: ", int(time.time() - start_time), " seconds")
|
37 |
+
return wavfile
|