import gradio as gr from transformers import pipeline import scipy import tempfile # Charger le pipeline text-to-speech avec le modèle suno/bark synthesiser = pipeline("text-to-speech", "suno/bark") def tts_infer(text): # Générer l'audio à partir du texte speech = synthesiser(text, forward_params={"do_sample": True}) # Sauvegarder l'audio dans un fichier temporaire WAV with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp: scipy.io.wavfile.write(fp.name, rate=speech["sampling_rate"], data=speech["audio"]) audio_path = fp.name return audio_path # Interface Gradio with gr.Blocks() as demo: gr.Markdown("# Text-to-Audio avec suno/bark 🐶\nEntrez un texte et écoutez le résultat !") with gr.Row(): with gr.Column(): text_input = gr.Textbox(label="Texte à synthétiser", placeholder="Tapez votre texte ici...", lines=2) run_btn = gr.Button("Générer l'audio") with gr.Column(): audio_output = gr.Audio(label="Audio généré", type="filepath") run_btn.click(fn=tts_infer, inputs=text_input, outputs=audio_output) if __name__ == "__main__": demo.launch()