Spaces:
Runtime error
Runtime error
File size: 1,079 Bytes
90010fe 9c824f7 90010fe 9c824f7 90010fe 9c824f7 90010fe 9c824f7 90010fe |
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 |
from tts_voice import tts_order_voice
import edge_tts
import gradio as gr
import tempfile
import anyio
language_dict = tts_order_voice
async def text_to_speech_edge(text, language_code):
voice = language_dict[language_code]
communicate = edge_tts.Communicate(text, voice)
with tempfile.NamedTemporaryFile(delete=False, suffix=".mp3") as tmp_file:
tmp_path = tmp_file.name
await communicate.save(tmp_path)
return "Speech synthesis completed:{}".format(text), tmp_path
input_text = gr.inputs.Textbox(lines=5, label="Input Text")
output_text = gr.outputs.Textbox(label="Output Text")
output_audio = gr.outputs.Audio(type="filepath", label="Export File")
default_language = list(language_dict.keys())[0]
language = gr.inputs.Dropdown(choices=list(language_dict.keys()), default=default_language, label="Language")
interface = gr.Interface(fn=text_to_speech_edge, inputs=[input_text, language], outputs=[output_text, output_audio], title="Edge TTS Text to Speech")
if __name__ == "__main__":
anyio.run(interface.launch, backend="asyncio") |