File size: 1,432 Bytes
e4b9f3b
 
 
 
 
 
74052bf
 
e4b9f3b
 
74052bf
e4b9f3b
 
 
74052bf
 
 
e4b9f3b
 
 
 
 
 
74052bf
 
 
e4b9f3b
 
 
 
 
 
 
74052bf
e4b9f3b
 
 
 
 
fad23ac
e4b9f3b
 
 
 
 
 
 
 
88b8d7c
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
import gradio as gr
import edge_tts
import asyncio
import tempfile
import os

# Default voice to be used
DEFAULT_VOICE = "en-US-AndrewMultilingualNeural"

# Text-to-speech function
async def text_to_speech(text, voice=DEFAULT_VOICE, rate=0, pitch=0):
    if not text.strip():
        return None, gr.Warning("Please enter text to convert.")
    
    rate_str = f"{rate:+d}%"
    pitch_str = f"{pitch:+d}Hz"
    communicate = edge_tts.Communicate(text, voice, rate=rate_str, pitch=pitch_str)
    with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
        tmp_path = tmp_file.name
        await communicate.save(tmp_path)
    return tmp_path, None

# Gradio interface function
def tts_interface(text):
    # Pass the default voice and default values for rate and pitch
    audio, warning = asyncio.run(text_to_speech(text))
    return audio, warning

# Create Gradio application
async def create_demo():
    demo = gr.Interface(
        fn=tts_interface,
        inputs=[
            gr.Textbox(label="Input Text", lines=5)
        ],
        outputs=[
            gr.Audio(label="Generated Audio", type="filepath"),
            gr.Markdown(label="Warning", visible=False)
        ],
        title="Elieon TeleText AI",
        analytics_enabled=False,
        allow_flagging=False
    )
    return demo

# Run the application
if __name__ == "__main__":
    demo = asyncio.run(create_demo())
    demo.launch()