Sahana31 commited on
Commit
e0aff3f
·
1 Parent(s): 8b71fc1

updated usecases

Browse files
Files changed (2) hide show
  1. app.py +30 -60
  2. voice_description_indian.json +64 -236
app.py CHANGED
@@ -1,37 +1,28 @@
 
1
  import gradio as gr
2
  import requests
3
- import json
4
  import logging
 
5
 
6
  # Configure logging
7
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
8
  logger = logging.getLogger(__name__)
9
 
10
- # Load voice descriptions from JSON file
11
- def load_voice_descriptions(file_path):
12
- try:
13
- with open(file_path, 'r') as file:
14
- return json.load(file)
15
- except FileNotFoundError:
16
- logger.error(f"File not found: {file_path}")
17
- return []
18
- except json.JSONDecodeError as e:
19
- logger.error(f"Failed to parse JSON: {e}")
20
- return []
21
 
22
  # Function to send text input to the API and retrieve the audio file
23
- def get_audio(input_text, voice_description_id):
24
  try:
25
- # Find the selected voice description
26
- selected_description = next((desc for desc in voice_descriptions if desc['userdomain_voice'] == voice_description_id), None)
27
-
28
- if selected_description:
29
- voice_description = selected_description['voice_description']
30
- output_file_name = selected_description['output_file_name']
31
- else:
32
- logger.error(f"Voice description not found for ID: {voice_description_id}")
33
- return f"Error: Voice description not found"
34
-
35
  # Define the API endpoint and headers
36
  url = "https://gaganyatri-indic-all-server.hf.space/v1/audio/speech"
37
  headers = {
@@ -53,15 +44,16 @@ def get_audio(input_text, voice_description_id):
53
  logger.info(f"API request successful. Status code: {response.status_code}")
54
 
55
  # Save the audio file
56
- with open(output_file_name, "wb") as audio_file:
 
57
  for chunk in response.iter_content(chunk_size=1024):
58
  if chunk:
59
  audio_file.write(chunk)
60
 
61
- logger.info(f"Audio file saved to: {output_file_name}")
62
 
63
  # Return the path to the saved audio file
64
- return output_file_name
65
  else:
66
  logger.error(f"API request failed. Status code: {response.status_code}, {response.text}")
67
  return f"Error: {response.status_code}, {response.text}"
@@ -72,41 +64,19 @@ def get_audio(input_text, voice_description_id):
72
  logger.error(f"General exception: {e}")
73
  return f"Error: {e}"
74
 
75
- # Load voice descriptions from JSON file
76
- voice_descriptions = load_voice_descriptions('voice_description_indian.json')
77
-
78
- # Extract IDs and descriptions for dropdown menu
79
- dropdown_choices = [(desc['userdomain_voice'], f"{desc['userdomain_voice']}: {desc['voice_description'][:50]}...") for desc in voice_descriptions]
80
-
81
- # Define the Gradio interface
82
- with gr.Blocks() as demo:
83
- gr.Markdown("### Text-to-Speech Generator")
84
-
85
- with gr.Row():
86
- input_text = gr.Textbox(label="Enter Text", placeholder="Type your text here...")
87
-
88
- with gr.Row():
89
- voice_dropdown = gr.Dropdown(
90
- choices=[choice[0] for choice in dropdown_choices],
91
- label="Select Voice Description",
92
- type="value",
93
- value=dropdown_choices[0][0] if dropdown_choices else None,
94
- interactive=True,
95
  )
96
-
97
- with gr.Row():
98
- output_audio = gr.Audio(label="Generated Audio")
99
-
100
- submit_button = gr.Button("Generate Audio")
101
-
102
- def process_request(input_text, voice_description_id):
103
- return get_audio(input_text, voice_description_id)
104
-
105
- submit_button.click(
106
- process_request,
107
- inputs=[input_text, voice_dropdown],
108
- outputs=[output_audio]
109
- )
110
 
111
  # Launch the Gradio demo
112
  try:
 
1
+
2
  import gradio as gr
3
  import requests
 
4
  import logging
5
+ import json
6
 
7
  # Configure logging
8
  logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
9
  logger = logging.getLogger(__name__)
10
 
11
+ # Load the JSON file containing use cases
12
+ with open("voice_description_indian.json", "r") as file:
13
+ usecases = json.load(file)
 
 
 
 
 
 
 
 
14
 
15
  # Function to send text input to the API and retrieve the audio file
16
+ def get_audio(input_text, usecase_id):
17
  try:
18
+ # Find the corresponding use case by ID
19
+ usecase = next((uc for uc in usecases["usecases"] if uc["id"] == usecase_id), None)
20
+ if not usecase:
21
+ return f"Error: Use case with ID {usecase_id} not found."
22
+
23
+ voice_description = usecase["voice_description"]
24
+ print(voice_description)
25
+ print(input_text)
 
 
26
  # Define the API endpoint and headers
27
  url = "https://gaganyatri-indic-all-server.hf.space/v1/audio/speech"
28
  headers = {
 
44
  logger.info(f"API request successful. Status code: {response.status_code}")
45
 
46
  # Save the audio file
47
+ audio_file_path = usecase["output_filename"]
48
+ with open(audio_file_path, "wb") as audio_file:
49
  for chunk in response.iter_content(chunk_size=1024):
50
  if chunk:
51
  audio_file.write(chunk)
52
 
53
+ logger.info(f"Audio file saved to: {audio_file_path}")
54
 
55
  # Return the path to the saved audio file
56
+ return audio_file_path
57
  else:
58
  logger.error(f"API request failed. Status code: {response.status_code}, {response.text}")
59
  return f"Error: {response.status_code}, {response.text}"
 
64
  logger.error(f"General exception: {e}")
65
  return f"Error: {e}"
66
 
67
+ # Define Gradio interface inputs and outputs
68
+ demo = gr.Interface(
69
+ fn=get_audio,
70
+ inputs=[
71
+ gr.Textbox(label="Enter Text", placeholder="Type your text here..."),
72
+ gr.Dropdown(
73
+ label="Select Use Case",
74
+ choices=[f"{uc['id']}: {uc['voice_description']}" for uc in usecases["usecases"]],
75
+ type="index"
 
 
 
 
 
 
 
 
 
 
 
76
  )
77
+ ],
78
+ outputs=gr.Audio(label="Generated Audio"),
79
+ )
 
 
 
 
 
 
 
 
 
 
 
80
 
81
  # Launch the Gradio demo
82
  try:
voice_description_indian.json CHANGED
@@ -1,236 +1,64 @@
1
- [
2
- {
3
- "id": 1,
4
- "voice_description": "A male voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing his very low-pitched voice with crisp clarity.",
5
- "output_file_name": "male_indian_very_low_pitch.mp3",
6
- "userdomain_voice": "male_indian_very_low_pitch"
7
- },
8
- {
9
- "id": 2,
10
- "voice_description": "A female voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing her quite low-pitched voice with crisp clarity.",
11
- "output_file_name": "female_indian_quite_low_pitch.mp3",
12
- "userdomain_voice": "female_indian_quite_low_pitch"
13
- },
14
- {
15
- "id": 3,
16
- "voice_description": "A male voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing his fairly low-pitched voice with crisp clarity.",
17
- "output_file_name": "male_indian_fairly_low_pitch.mp3",
18
- "userdomain_voice": "male_indian_fairly_low_pitch"
19
- },
20
- {
21
- "id": 4,
22
- "voice_description": "A female voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing her slightly low-pitched voice with crisp clarity.",
23
- "output_file_name": "female_indian_slightly_low_pitch.mp3",
24
- "userdomain_voice": "female_indian_slightly_low_pitch"
25
- },
26
- {
27
- "id": 5,
28
- "voice_description": "A female voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing her slightly high-pitched voice with crisp clarity.",
29
- "output_file_name": "female_indian_slightly_high_pitch.mp3",
30
- "userdomain_voice": "female_indian_slightly_high_pitch"
31
- },
32
- {
33
- "id": 6,
34
- "voice_description": "A male voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing his fairly high-pitched voice with crisp clarity.",
35
- "output_file_name": "male_indian_fairly_high_pitch.mp3",
36
- "userdomain_voice": "male_indian_fairly_high_pitch"
37
- },
38
- {
39
- "id": 7,
40
- "voice_description": "A female voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing her quite high-pitched voice with crisp clarity.",
41
- "output_file_name": "female_indian_quite_high_pitch.mp3",
42
- "userdomain_voice": "female_indian_quite_high_pitch"
43
- },
44
- {
45
- "id": 8,
46
- "voice_description": "A male voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing his very high-pitched voice with crisp clarity.",
47
- "output_file_name": "male_indian_very_high_pitch.mp3",
48
- "userdomain_voice": "male_indian_very_high_pitch"
49
- },
50
- {
51
- "id": 9,
52
- "voice_description": "A female voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing her voice with crisp clarity. Her tone is very monotone.",
53
- "output_file_name": "female_indian_monotone.mp3",
54
- "userdomain_voice": "female_indian_monotone"
55
- },
56
- {
57
- "id": 10,
58
- "voice_description": "A female voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing her voice with crisp clarity. Her tone is quite monotone.",
59
- "output_file_name": "female_indian_quite_monotone.mp3",
60
- "userdomain_voice": "female_indian_quite_monotone"
61
- },
62
- {
63
- "id": 11,
64
- "voice_description": "A male voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing his voice with crisp clarity. His tone is fairly monotone.",
65
- "output_file_name": "male_indian_fairly_monotone.mp3",
66
- "userdomain_voice": "male_indian_fairly_monotone"
67
- },
68
- {
69
- "id": 12,
70
- "voice_description": "A female voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing her voice with crisp clarity. Her tone is slightly monotone.",
71
- "output_file_name": "female_indian_slightly_monotone.mp3",
72
- "userdomain_voice": "female_indian_slightly_monotone"
73
- },
74
- {
75
- "id": 13,
76
- "voice_description": "A male voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing his voice with crisp clarity. His tone is slightly expressive and animated.",
77
- "output_file_name": "male_indian_slightly_expressive.mp3",
78
- "userdomain_voice": "male_indian_slightly_expressive"
79
- },
80
- {
81
- "id": 14,
82
- "voice_description": "A female voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing her voice with crisp clarity. Her tone is fairly expressive and animated.",
83
- "output_file_name": "female_indian_fairly_expressive.mp3",
84
- "userdomain_voice": "female_indian_fairly_expressive"
85
- },
86
- {
87
- "id": 15,
88
- "voice_description": "A male voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing his voice with crisp clarity. His tone is quite expressive and animated.",
89
- "output_file_name": "male_indian_quite_expressive.mp3",
90
- "userdomain_voice": "male_indian_quite_expressive"
91
- },
92
- {
93
- "id": 16,
94
- "voice_description": "A female voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing her voice with crisp clarity. Her tone is very expressive and animated.",
95
- "output_file_name": "female_indian_very_expressive.mp3",
96
- "userdomain_voice": "female_indian_very_expressive"
97
- },
98
- {
99
- "id": 17,
100
- "voice_description": "A male voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing his voice with crisp clarity. He reads the book very slowly.",
101
- "output_file_name": "male_indian_very_slow.mp3",
102
- "userdomain_voice": "male_indian_very_slow"
103
- },
104
- {
105
- "id": 18,
106
- "voice_description": "A female voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing her voice with crisp clarity. She reads the book quite slowly.",
107
- "output_file_name": "female_indian_quite_slow.mp3",
108
- "userdomain_voice": "female_indian_quite_slow"
109
- },
110
- {
111
- "id": 19,
112
- "voice_description": "A male voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing his voice with crisp clarity. He reads the book fairly slowly.",
113
- "output_file_name": "male_indian_fairly_slow.mp3",
114
- "userdomain_voice": "male_indian_fairly_slow"
115
- },
116
- {
117
- "id": 20,
118
- "voice_description": "A female voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing her voice with crisp clarity. She reads the book slightly slowly.",
119
- "output_file_name": "female_indian_slightly_slow.mp3",
120
- "userdomain_voice": "female_indian_slightly_slow"
121
- },
122
- {
123
- "id": 21,
124
- "voice_description": "A male voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing his voice with crisp clarity. He reads the book slightly quickly.",
125
- "output_file_name": "male_indian_slightly_quick.mp3",
126
- "userdomain_voice": "male_indian_slightly_quick"
127
- },
128
- {
129
- "id": 22,
130
- "voice_description": "A female voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing her voice with crisp clarity. She reads the book fairly quickly.",
131
- "output_file_name": "female_indian_fairly_quick.mp3",
132
- "userdomain_voice": "female_indian_fairly_quick"
133
- },
134
- {
135
- "id": 23,
136
- "voice_description": "A male voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing his voice with crisp clarity. He reads the book quite quickly.",
137
- "output_file_name": "male_indian_quite_quick.mp3",
138
- "userdomain_voice": "male_indian_quite_quick"
139
- },
140
- {
141
- "id": 24,
142
- "voice_description": "A female voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing her voice with crisp clarity. She reads the book very quickly.",
143
- "output_file_name": "female_indian_very_quick.mp3",
144
- "userdomain_voice": "female_indian_very_quick"
145
- },
146
- {
147
- "id": 25,
148
- "voice_description": "A male voice with an Indian accent enunciates every word with precision. The recording is very bad, and the speaker's voice is very distant-sounding and noisy.",
149
- "output_file_name": "male_indian_bad_recording.mp3",
150
- "userdomain_voice": "male_indian_bad_recording"
151
- },
152
- {
153
- "id": 26,
154
- "voice_description": "A female voice with an Indian accent enunciates every word with precision. The speaker's voice is quite close-sounding but very noisy.",
155
- "output_file_name": "female_indian_noisy.mp3",
156
- "userdomain_voice": "female_indian_noisy"
157
- },
158
- {
159
- "id": 27,
160
- "voice_description": "A male voice with an Indian accent enunciates every word with precision. The speaker's voice is close-sounding but fairly noisy.",
161
- "output_file_name": "male_indian_fairly_noisy.mp3",
162
- "userdomain_voice": "male_indian_fairly_noisy"
163
- },
164
- {
165
- "id": 28,
166
- "voice_description": "A male voice with an Indian accent enunciates every word with precision. The speaker's voice is fairly distant-sounding.",
167
- "output_file_name": "male_indian_fairly_distant.mp3",
168
- "userdomain_voice": "male_indian_fairly_distant"
169
- },
170
- {
171
- "id": 29,
172
- "voice_description": "A female voice with an Indian accent enunciates every word with precision. The speaker's voice is slightly distant-sounding.",
173
- "output_file_name": "female_indian_slightly_distant.mp3",
174
- "userdomain_voice": "female_indian_slightly_distant"
175
- },
176
- {
177
- "id": 30,
178
- "voice_description": "A male voice with an Indian accent enunciates every word with precision. The speaker's voice is fairly close-sounding.",
179
- "output_file_name": "male_indian_fairly_close.mp3",
180
- "userdomain_voice": "male_indian_fairly_close"
181
- },
182
- {
183
- "id": 31,
184
- "voice_description": "A male voice with an Indian accent enunciates every word with precision. The speaker's voice is quite close-sounding and quite clean.",
185
- "output_file_name": "male_indian_quite_clean.mp3",
186
- "userdomain_voice": "male_indian_quite_clean"
187
- },
188
- {
189
- "id": 32,
190
- "voice_description": "A female voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding and clean, and the recording is excellent, capturing her voice with crisp clarity.",
191
- "output_file_name": "female_indian_clean.mp3",
192
- "userdomain_voice": "female_indian_clean"
193
- },
194
- {
195
- "id": 33,
196
- "voice_description": "A male voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing his voice with crisp clarity.",
197
- "output_file_name": "male_indian_accent.mp3",
198
- "userdomain_voice": "male_indian_accent"
199
- },
200
- {
201
- "id": 34,
202
- "voice_description": "A male voice with an English accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing his voice with crisp clarity.",
203
- "output_file_name": "male_english_accent.mp3",
204
- "userdomain_voice": "male_english_accent"
205
- },
206
- {
207
- "id": 35,
208
- "voice_description": "A male voice with a Pakistani accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing his voice with crisp clarity.",
209
- "output_file_name": "male_pakistani_accent.mp3",
210
- "userdomain_voice": "male_pakistani_accent"
211
- },
212
- {
213
- "id": 36,
214
- "voice_description": "A female voice with an Italian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing her voice with crisp clarity.",
215
- "output_file_name": "female_italian_accent.mp3",
216
- "userdomain_voice": "female_italian_accent"
217
- },
218
- {
219
- "id": 37,
220
- "voice_description": "A male voice with a South African accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing his voice with crisp clarity.",
221
- "output_file_name": "male_south_african_accent.mp3",
222
- "userdomain_voice": "male_south_african_accent"
223
- },
224
- {
225
- "id": 38,
226
- "voice_description": "A male voice with a Canadian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing his voice with crisp clarity.",
227
- "output_file_name": "male_canadian_accent.mp3",
228
- "userdomain_voice": "male_canadian_accent"
229
- },
230
- {
231
- "id": 39,
232
- "voice_description": "A female voice with an Indian accent enunciates every word with precision. The speaker's voice is very close-sounding, and the recording is excellent, capturing her voice with crisp clarity.",
233
- "output_file_name": "female_indian_accent.mp3",
234
- "userdomain_voice": "female_indian_accent"
235
- }
236
- ]
 
1
+ {
2
+ "usecases": [
3
+ {
4
+ "id": 0,
5
+ "voice_description": "Anu greeting a customer in a retail store",
6
+ "user_domain_voice": "Retail",
7
+ "output_filename": "anu_greeting_customer.mp3"
8
+ },
9
+ {
10
+ "id": 1,
11
+ "voice_description": "Suresh providing weather updates",
12
+ "user_domain_voice": "Weather",
13
+ "output_filename": "suresh_weather_update.mp3"
14
+ },
15
+ {
16
+ "id": 2,
17
+ "voice_description": "Anu assisting with online banking queries",
18
+ "user_domain_voice": "Banking",
19
+ "output_filename": "anu_banking_assistance.mp3"
20
+ },
21
+ {
22
+ "id": 3,
23
+ "voice_description": "Suresh narrating a news bulletin",
24
+ "user_domain_voice": "News",
25
+ "output_filename": "suresh_news_bulletin.mp3"
26
+ },
27
+ {
28
+ "id": 4,
29
+ "voice_description": "Anu guiding through a mobile app tutorial",
30
+ "user_domain_voice": "Technology",
31
+ "output_filename": "anu_app_tutorial.mp3"
32
+ },
33
+ {
34
+ "id": 5,
35
+ "voice_description": "Suresh explaining a recipe step-by-step",
36
+ "user_domain_voice": "Cooking",
37
+ "output_filename": "suresh_recipe_explanation.mp3"
38
+ },
39
+ {
40
+ "id": 6,
41
+ "voice_description": "Anu answering frequently asked questions in healthcare",
42
+ "user_domain_voice": "Healthcare",
43
+ "output_filename": "anu_healthcare_faq.mp3"
44
+ },
45
+ {
46
+ "id": 7,
47
+ "voice_description": "Suresh narrating an audiobook chapter",
48
+ "user_domain_voice": "Entertainment",
49
+ "output_filename": "suresh_audiobook_chapter.mp3"
50
+ },
51
+ {
52
+ "id": 8,
53
+ "voice_description": "Anu giving instructions for a workout session",
54
+ "user_domain_voice": "Fitness",
55
+ "output_filename": "anu_workout_instructions.mp3"
56
+ },
57
+ {
58
+ "id": 9,
59
+ "voice_description": "Suresh providing customer support for an e-commerce platform",
60
+ "user_domain_voice": "E-commerce",
61
+ "output_filename": "suresh_customer_support.mp3"
62
+ }
63
+ ]
64
+ }