dhanishetty commited on
Commit
d80a8a6
·
verified ·
1 Parent(s): 4a483eb

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +53 -0
app.py ADDED
@@ -0,0 +1,53 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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, statements):
8
+ if (SpeechRegion == '' or SpeechKey == '' or statements == ''):
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
+ text = tuple(statements)
20
+
21
+ with tempfile.NamedTemporaryFile(suffix=".mp3", delete=False) as temp_file:
22
+ temp_file.write(speech_synthesizer.speak_text_async(text).get())
23
+
24
+ temp_file_path = temp_file.name
25
+ output = temp_file_path
26
+ except :
27
+ output = next_alert
28
+ return output
29
+
30
+
31
+ with gr.Blocks() as demo:
32
+ gr.Markdown("# TTS Text To Speech using OpenAI ")
33
+
34
+ text1 = gr.Textbox(type = 'password',label="Enter your Speech Region", placeholder="Speech Region", lines=1)
35
+
36
+ text2 = gr.Textbox(label="SpeechKey",placeholder="Enter your Speech Key")
37
+ text3 = gr.Textbox(label="Inputs",placeholder="Enter your Inputs")
38
+
39
+
40
+
41
+
42
+
43
+ gr.Interface(
44
+ Txt_To_Speech,
45
+ [
46
+ text1,text2,text3
47
+ ],
48
+ outputs=gr.Audio(label="Speech Output")
49
+ )
50
+
51
+
52
+
53
+ demo.launch()