Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,30 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
from
|
|
|
|
|
|
|
| 3 |
import numpy as np
|
| 4 |
-
import
|
| 5 |
|
| 6 |
-
# Charger le modèle
|
| 7 |
-
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def text_to_speech(text):
|
| 10 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
output_path = "output.wav"
|
| 12 |
-
|
| 13 |
|
| 14 |
return output_path
|
| 15 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from transformers import AutoModel, AutoTokenizer
|
| 3 |
+
import torch
|
| 4 |
+
import scipy.io.wavfile as wavfile
|
| 5 |
import numpy as np
|
| 6 |
+
import os
|
| 7 |
|
| 8 |
+
# Charger le modèle depuis Hugging Face
|
| 9 |
+
model_name = "2Noise/ChatTTS"
|
| 10 |
+
model = AutoModel.from_pretrained(model_name)
|
| 11 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 12 |
|
| 13 |
def text_to_speech(text):
|
| 14 |
+
# Tokenisation du texte
|
| 15 |
+
inputs = tokenizer(text, return_tensors="pt")
|
| 16 |
+
|
| 17 |
+
# Génération de l'audio
|
| 18 |
+
with torch.no_grad():
|
| 19 |
+
outputs = model(**inputs)
|
| 20 |
+
|
| 21 |
+
# Récupération des données audio
|
| 22 |
+
audio = outputs.last_hidden_state.squeeze().cpu().numpy()
|
| 23 |
+
|
| 24 |
+
# Normalisation et conversion en int16 pour l'enregistrement WAV
|
| 25 |
+
audio = (audio * 32767).astype(np.int16)
|
| 26 |
output_path = "output.wav"
|
| 27 |
+
wavfile.write(output_path, 22050, audio)
|
| 28 |
|
| 29 |
return output_path
|
| 30 |
|