File size: 2,599 Bytes
c9297fa
b23d86c
c9297fa
 
b23d86c
df5b239
c9297fa
51023f8
 
 
 
 
 
 
 
 
 
 
 
 
34960c0
51023f8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
c9297fa
b23d86c
c9297fa
 
 
 
 
 
 
b23d86c
03a56f9
 
 
038f52f
b23d86c
b6aed11
6222f8f
 
 
 
 
 
 
 
 
 
 
 
 
 
f6a5f10
c9297fa
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import edge_tts
import gradio as gr
import tempfile
import anyio


language_dict = {
    'Abeo': 'en-NG-AbeoNeural',
    'Ana': 'en-US-AnaNeural',
    'Andrew': 'en-US-AndrewNeural',
    'Aria': 'en-US-AriaNeural',
    'Asilia': 'en-KE-AsiliaNeural',
    'Ava': 'en-US-AvaNeural',
    'Brian': 'en-US-BrianNeural',
    'Christopher': 'en-US-ChristopherNeural',
    'Chilemba': 'en-KE-ChilembaNeural',
    'Clara': 'en-CA-ClaraNeural',
    'Connor': 'en-IE-ConnorNeural',
    'Emily': 'en-IE-EmilyNeural',
    'Elimu': 'en-TZ-ElimuNeural',
    'Emma': 'en-US-EmmaMultilingualNeural',
    'Eric': 'en-US-EricNeural',
    'Ezinne': 'en-NG-EzinneNeural',
    'Guy': 'en-US-GuyNeural',
    'Imani': 'en-TZ-ImaniNeural',
    'James': 'en-PH-JamesNeural',
    'Jenny': 'en-US-JennyNeural',
    'Leah': 'en-ZA-LeahNeural',
    'Libby': 'en-GB-LibbyNeural',
    'Liam': 'en-CA-LiamNeural',
    'Luke': 'en-ZA-LukeNeural',
    'Luna': 'en-SG-LunaNeural',
    'Maisie': 'en-GB-MaisieNeural',
    'Michelle': 'en-US-MichelleNeural',
    'Mitchell': 'en-NZ-MitchellNeural',
    'Molly': 'en-NZ-MollyNeural',
    'Natasha': 'en-AU-NatashaNeural',
    'Neerja': 'en-IN-NeerjaExpressiveNeural',
    'Prabhat': 'en-IN-PrabhatNeural',
    'Roger': 'en-US-RogerNeural',
    'Rosa': 'en-PH-RosaNeural',
    'Ryan': 'en-GB-RyanNeural',
    'Sam': 'en-HK-SamNeural',
    'Sonia': 'en-GB-SoniaNeural',
    'Steffan': 'en-US-SteffanNeural',
    'Thomas': 'en-GB-ThomasNeural',
    'Wayne': 'en-SG-WayneNeural',
    'William': 'en-AU-WilliamNeural',
    'Yan': 'en-HK-YanNeural'
}

async def text_to_speech_edge(text, language_code):
    voice = language_dict.get(language_code, "default_voice")
    communicate = edge_tts.Communicate(text, voice)
    with tempfile.NamedTemporaryFile(delete=False, suffix=".wav") as tmp_file:
        tmp_path = tmp_file.name
        await communicate.save(tmp_path)
    return f"Speech synthesis completed for: {text}", tmp_path

input_text = gr.Textbox(lines=5, label="Input Text")
output_text = gr.Textbox(label="Output Text")
output_audio = gr.Audio(type="filepath", label="Exported Audio")
language = gr.Dropdown(choices=list(language_dict.keys()), label="Choose the Voice Model")


# Gradio interface
iface = gr.Blocks()

with iface:
    
    gr.Interface(
        fn=text_to_speech_edge,
        inputs=[input_text, language],
        outputs=[output_text, output_audio],
        title="Edge TTS",
        description="Microsoft Edge Text-To-Speech (Forked & Fixed Ilaria TTS)",
    )
    
iface.launch()

if __name__ == "__main__":
    anyio.run(interface.launch, backend="asyncio")