Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| from transformers import AutoModel, AutoTokenizer | |
| import torch | |
| import scipy.io.wavfile as wavfile | |
| import numpy as np | |
| import os | |
| # Charger le modèle depuis Hugging Face | |
| model_name = "2Noise/ChatTTS" | |
| model = AutoModel.from_pretrained(model_name) | |
| tokenizer = AutoTokenizer.from_pretrained(model_name) | |
| def text_to_speech(text): | |
| # Tokenisation du texte | |
| inputs = tokenizer(text, return_tensors="pt") | |
| # Génération de l'audio | |
| with torch.no_grad(): | |
| outputs = model(**inputs) | |
| # Récupération des données audio | |
| audio = outputs.last_hidden_state.squeeze().cpu().numpy() | |
| # Normalisation et conversion en int16 pour l'enregistrement WAV | |
| audio = (audio * 32767).astype(np.int16) | |
| output_path = "output.wav" | |
| wavfile.write(output_path, 22050, audio) | |
| return output_path | |
| # Interface Gradio | |
| interface = gr.Interface( | |
| fn=text_to_speech, | |
| inputs=gr.Textbox(label="Entrez votre texte ici"), | |
| outputs=gr.Audio(type="filepath"), | |
| title="ChatTTS - Synthèse Vocale", | |
| description="Entrez un texte et écoutez la voix générée avec ChatTTS." | |
| ) | |
| # Lancer l'application | |
| interface.launch() | |