Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoModelForSpeechSeq2Seq, AutoProcessor
|
| 3 |
+
import torch
|
| 4 |
+
import scipy.io.wavfile
|
| 5 |
+
|
| 6 |
+
# Charger le modèle et le processeur
|
| 7 |
+
model_name = "2Noise/ChatTTS"
|
| 8 |
+
processor = AutoProcessor.from_pretrained(model_name)
|
| 9 |
+
model = AutoModelForSpeechSeq2Seq.from_pretrained(model_name).to("cpu")
|
| 10 |
+
|
| 11 |
+
def text_to_speech(text):
|
| 12 |
+
# Préparer le texte
|
| 13 |
+
inputs = processor(text, return_tensors="pt")
|
| 14 |
+
|
| 15 |
+
# Générer l'audio
|
| 16 |
+
with torch.no_grad():
|
| 17 |
+
outputs = model.generate(inputs.input_ids)
|
| 18 |
+
|
| 19 |
+
# Convertir en signal audio
|
| 20 |
+
audio = processor.batch_decode(outputs, skip_special_tokens=True)[0]
|
| 21 |
+
|
| 22 |
+
# Sauvegarder en fichier WAV
|
| 23 |
+
output_path = "output.wav"
|
| 24 |
+
scipy.io.wavfile.write(output_path, 22050, audio)
|
| 25 |
+
|
| 26 |
+
return output_path
|
| 27 |
+
|
| 28 |
+
# Créer l'interface Gradio
|
| 29 |
+
interface = gr.Interface(
|
| 30 |
+
fn=text_to_speech,
|
| 31 |
+
inputs=gr.Textbox(label="Entrez votre texte ici"),
|
| 32 |
+
outputs=gr.Audio(type="filepath"),
|
| 33 |
+
title="ChatTTS - Générateur de Voix",
|
| 34 |
+
description="Ce modèle convertit votre texte en voix synthétique."
|
| 35 |
+
)
|
| 36 |
+
|
| 37 |
+
# Lancer l'application
|
| 38 |
+
interface.launch()
|