File size: 672 Bytes
b23d86c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f6a5f10
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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))


voice_options = ["en-US-JennyNeural", "en-US-GuyNeural"]

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