Spaces:
Runtime error
Runtime error
anyantudre
commited on
Commit
•
ca6951f
1
Parent(s):
f2e201e
Update goai_tts.py
Browse files- goai_tts.py +8 -10
goai_tts.py
CHANGED
@@ -1,11 +1,7 @@
|
|
1 |
-
import torch
|
2 |
-
import scipy
|
3 |
import time
|
4 |
import numpy as np
|
5 |
-
|
6 |
-
|
7 |
-
device = 0 if torch.cuda.is_available() else "cpu"
|
8 |
-
|
9 |
|
10 |
def goai_tts(texte):
|
11 |
"""
|
@@ -18,7 +14,7 @@ def goai_tts(texte):
|
|
18 |
|
19 |
Return
|
20 |
------
|
21 |
-
|
22 |
"""
|
23 |
|
24 |
### assurer la reproductibilité
|
@@ -28,12 +24,14 @@ def goai_tts(texte):
|
|
28 |
|
29 |
### charger le modèle TTS
|
30 |
model_id = "anyantudre/mms-tts-mos-V1"
|
31 |
-
synthesiser = pipeline("text-to-speech", model_id, device=device)
|
32 |
|
33 |
### inférence
|
34 |
speech = synthesiser(texte)
|
35 |
-
|
|
|
|
|
36 |
|
37 |
print("Temps écoulé: ", int(time.time() - start_time), " secondes")
|
38 |
|
39 |
-
return
|
|
|
|
|
|
|
1 |
import time
|
2 |
import numpy as np
|
3 |
+
import scipy.io.wavfile
|
4 |
+
from transformers import pipeline, set_seed
|
|
|
|
|
5 |
|
6 |
def goai_tts(texte):
|
7 |
"""
|
|
|
14 |
|
15 |
Return
|
16 |
------
|
17 |
+
Un tuple contenant le taux d'échantillonnage et les données audio sous forme de tableau numpy.
|
18 |
"""
|
19 |
|
20 |
### assurer la reproductibilité
|
|
|
24 |
|
25 |
### charger le modèle TTS
|
26 |
model_id = "anyantudre/mms-tts-mos-V1"
|
27 |
+
synthesiser = pipeline("text-to-speech", model_id, device=device)
|
28 |
|
29 |
### inférence
|
30 |
speech = synthesiser(texte)
|
31 |
+
|
32 |
+
sample_rate = speech["sampling_rate"]
|
33 |
+
audio_data = np.array(speech["audio"][0], dtype=float)
|
34 |
|
35 |
print("Temps écoulé: ", int(time.time() - start_time), " secondes")
|
36 |
|
37 |
+
return sample_rate, audio_data
|