File size: 586 Bytes
b23d86c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import gradio as gr

def text_to_speech(text, voice):
    import subprocess
    import audiosegment
    from IPython.display import Audio, display

    command = ['edge-tts', '--voice', voice, '--text', text,
               '--write-media', 'edge.mp3', '--write-subtitles', 'edge.vtt']

    result = subprocess.run(command, stdout=subprocess.PIPE, text=True)
    print(result.stdout)

    try:
        display(Audio("edge.mp3", autoplay=True))
    except Exception as e:
        print("Error:", str(e))

gr.Interface(fn=text_to_speech, inputs=["text", "text"], outputs="audio").launch()