tojonatolotra commited on
Commit
e6a5b75
·
verified ·
1 Parent(s): 60afc15

Create app.py

Browse files

📄 Add file app.py

Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+ import scipy
4
+ import tempfile
5
+
6
+ # Charger le pipeline text-to-speech avec le modèle suno/bark
7
+ synthesiser = pipeline("text-to-speech", "suno/bark")
8
+
9
+ def tts_infer(text):
10
+ # Générer l'audio à partir du texte
11
+ speech = synthesiser(text, forward_params={"do_sample": True})
12
+ # Sauvegarder l'audio dans un fichier temporaire WAV
13
+ with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as fp:
14
+ scipy.io.wavfile.write(fp.name, rate=speech["sampling_rate"], data=speech["audio"])
15
+ audio_path = fp.name
16
+ return audio_path
17
+
18
+ # Interface Gradio
19
+ with gr.Blocks() as demo:
20
+ gr.Markdown("# Text-to-Audio avec suno/bark 🐶\nEntrez un texte et écoutez le résultat !")
21
+ with gr.Row():
22
+ with gr.Column():
23
+ text_input = gr.Textbox(label="Texte à synthétiser", placeholder="Tapez votre texte ici...", lines=2)
24
+ run_btn = gr.Button("Générer l'audio")
25
+ with gr.Column():
26
+ audio_output = gr.Audio(label="Audio généré", type="filepath")
27
+ run_btn.click(fn=tts_infer, inputs=text_input, outputs=audio_output)
28
+
29
+ if __name__ == "__main__":
30
+ demo.launch()