Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import tempfile
|
| 3 |
+
import azure.cognitiveservices.speech as speechsdk
|
| 4 |
+
first_alert = "first.wav"
|
| 5 |
+
next_alert = "next.wav"
|
| 6 |
+
|
| 7 |
+
def Txt_To_Speech(SpeechRegion, SpeechKey, text):
|
| 8 |
+
if (SpeechRegion == '' or SpeechKey == '' or text == ''):
|
| 9 |
+
output= first_alert
|
| 10 |
+
else:
|
| 11 |
+
try:
|
| 12 |
+
speech_config = speechsdk.SpeechConfig(subscription= SpeechKey, region=SpeechRegion)
|
| 13 |
+
audio_config = speechsdk.audio.AudioOutputConfig(use_default_speaker=True)
|
| 14 |
+
|
| 15 |
+
speech_config.speech_synthesis_voice_name='en-US-JennyNeural'
|
| 16 |
+
|
| 17 |
+
speech_synthesizer = speechsdk.SpeechSynthesizer(speech_config=speech_config, audio_config=audio_config)
|
| 18 |
+
|
| 19 |
+
result = speech_synthesizer.speak_text_async(text).get()
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
stream = speechsdk.AudioDataStream(result = result)
|
| 23 |
+
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as temp_file:
|
| 24 |
+
stream.save_to_wav_file(temp_file.name)
|
| 25 |
+
temp_file_path = temp_file.name
|
| 26 |
+
|
| 27 |
+
output = temp_file_path
|
| 28 |
+
except :
|
| 29 |
+
output = next_alert
|
| 30 |
+
return output
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
with gr.Blocks() as demo:
|
| 34 |
+
gr.Markdown("# TTS Text To Speech using OpenAI ")
|
| 35 |
+
|
| 36 |
+
text1 = gr.Textbox(type = 'password',label="Enter your Speech Region", placeholder="Speech Region", lines=1)
|
| 37 |
+
text2 = gr.Textbox(label="SpeechKey",placeholder="Enter your Speech Key")
|
| 38 |
+
text3 = gr.Textbox(label="Inputs",placeholder="Enter your Inputs")
|
| 39 |
+
|
| 40 |
+
gr.Interface(
|
| 41 |
+
Txt_To_Speech,
|
| 42 |
+
[
|
| 43 |
+
text1,text2,text3
|
| 44 |
+
],
|
| 45 |
+
outputs=gr.Audio(label="Speech Output")
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
demo.launch()
|