Spaces:
Build error
Build error
File size: 1,605 Bytes
a854603 |
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 |
import edge_tts
import gradio as gr
import tempfile
language_dict = {
'English-Jenny (Female)': 'en-US-JennyNeural',
}
async def text_to_speech_edge(text, language_code, rate, volume, pitch):
voice = language_dict.get(language_code, "default_voice")
rates = "+" + str(rate) + "%" if rate >= 0 else str(rate) + "%"
volumes = "+" + str(volume) + "%" if volume >= 0 else str(volume) + "%"
pitchs = "+" + str(pitch) + "Hz" if pitch >= 0 else str(pitch) + "Hz"
communicate = edge_tts.Communicate(text, voice, rate=rates, volume=volumes, pitch=pitchs, proxy=None)
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")
rate = gr.Slider(-100, 100,step=1,value=0,label="Rate",info="Rate",interactive=True)
volume = gr.Slider(-100,100,step=1,value=0,label="Volume",info="Volume",interactive=True)
pitch = gr.Slider(-100,100,step=1,value=0,label="Pitch",info="Pitch",interactive=True)
interface = gr.Interface(
fn=text_to_speech_edge,
inputs=[input_text, language, rate, volume,pitch],
outputs=[output_text, output_audio],
title="Edge-TTS",
description="Microsoft Edge Text-To-Speech (Created by Yash Chouhan)",
)
interface.launch(share=True) |