manzing commited on
Commit
f12783b
1 Parent(s): c3d2372

Upload appweb.py

Browse files
Files changed (1) hide show
  1. appweb.py +105 -0
appweb.py ADDED
@@ -0,0 +1,105 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import edge_tts
3
+ import asyncio
4
+ import os
5
+ # https://speech.platform.bing.com/consumer/speech/synthesize/readaloud/voices/list?trustedclienttoken=6A5AA1D4EAFF4E9FB37E23D68491D6F4
6
+ SUPPORTED_VOICES = {
7
+ 'Vivienne': 'fr-FR-VivienneMultilingualNeural',
8
+ 'Denise': 'fr-FR-DeniseNeural',
9
+ 'Eloise': 'fr-FR-EloiseNeural',
10
+ 'Remy': 'fr-FR-RemyMultilingualNeural',
11
+ 'Henri': 'fr-FR-HenriNeural'
12
+ }
13
+
14
+ # Modification de voix
15
+ def changeVoice(voices):
16
+ example = SUPPORTED_VOICES[voices]
17
+ example_file = os.path.join(os.path.dirname(__file__), "example/"+example+".mp3")
18
+ return example_file
19
+
20
+ # Text to Speech
21
+ async def textToSpeech(text, voices, rate, volume):
22
+ output_file = "output.mp3"
23
+ voices = SUPPORTED_VOICES[voices]
24
+ if (rate >= 0):
25
+ rates = rate = "+" + str(rate) + "%"
26
+ else:
27
+ rates = str(rate) + "%"
28
+ if (volume >= 0):
29
+ volumes = "+" + str(volume) + "%"
30
+ else:
31
+ volumes = str(volume) + "%"
32
+ communicate = edge_tts.Communicate(text,
33
+ voices,
34
+ rate=rates,
35
+ volume=volumes,
36
+ proxy=None)
37
+ await communicate.save(output_file)
38
+ audio_file = os.path.join(os.path.dirname(__file__), "output.mp3")
39
+ if (os.path.exists(audio_file)):
40
+ return audio_file
41
+ else:
42
+ raise gr.Error("La création a échoué!")
43
+ return FileNotFoundError
44
+
45
+
46
+ # Effacer le texte et rendu
47
+ def clearSpeech():
48
+ output_file = os.path.join(os.path.dirname(__file__), "output.mp3")
49
+ if (os.path.exists(output_file)):
50
+ os.remove(output_file)
51
+ return None, None
52
+
53
+
54
+ with gr.Blocks(css="style.css", title="Text To Speech") as demo:
55
+ gr.Markdown("""
56
+ # Text-to-Speech FR
57
+ Conversion texte en audio vocal avec edge-tts
58
+ """)
59
+ with gr.Row():
60
+ with gr.Column():
61
+ text = gr.TextArea(label="Entrez votre texte", elem_classes="text-area")
62
+ btn = gr.Button("Convertir en audio vocal", elem_id="submit-btn")
63
+ with gr.Column():
64
+ voices = gr.Dropdown(choices=[
65
+ "Vivienne", "Denise", "Eloise", "Remy",
66
+ "Henri"
67
+ ],
68
+ value="Vivienne",
69
+ label="Modèle de voix",
70
+ info="Choix du modèle vocal FR (France)",
71
+ interactive=True)
72
+
73
+ example = gr.Audio(label="Exemple",
74
+ value="example/fr-FR-VivienneMultilingualNeural.mp3",
75
+ interactive=False,
76
+ autoplay=False,
77
+ elem_classes="example")
78
+
79
+ voices.change(fn=changeVoice,inputs=voices,outputs=example)
80
+ rate = gr.Slider(-100,
81
+ 100,
82
+ step=1,
83
+ value=0,
84
+ label="Vitesse de parole",
85
+ info="Accélérer ou ralentir la voix",
86
+ interactive=True)
87
+
88
+ volume = gr.Slider(-100,
89
+ 100,
90
+ step=1,
91
+ value=0,
92
+ label="Volume",
93
+ info="Augmenter ou baisser le volume audio",
94
+ interactive=True)
95
+ audio = gr.Audio(label="Rendu audio",
96
+ interactive=False,
97
+ elem_classes="audio")
98
+ clear = gr.Button("Effacer", elem_id="clear-btn")
99
+ btn.click(fn=textToSpeech,
100
+ inputs=[text, voices, rate, volume],
101
+ outputs=[audio])
102
+ clear.click(fn=clearSpeech, outputs=[text, audio])
103
+
104
+ if __name__ == "__main__":
105
+ demo.launch()