utkarsh2299 commited on
Commit
1fbbb1c
·
verified ·
1 Parent(s): 2f16988

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -29
app.py CHANGED
@@ -17,32 +17,77 @@ lang = st.selectbox("Select language", lang_options)
17
  gender_options = ['Female', 'Male']
18
  gender = st.selectbox("Select gender", gender_options)
19
 
20
- # Button to trigger TTS
21
- if st.button("Generate Speech"):
22
- # API URL
23
- url = "https://asr.iitm.ac.in/tts/hindi/male/" # Change this to your API URL
24
-
25
- # Prepare payload
26
- payload = {
27
- "input": text,
28
- "gender": gender.lower(),
29
- "lang": lang.lower(),
30
- "alpha": 1,
31
- "segmentwise": "True"
32
- }
33
-
34
- # Make API request
35
- response = requests.post(url, json=payload)
36
-
37
- # Handle response
38
- if response.status_code == 200:
39
- # Decode audio
40
- audio = response.json()['audio']
41
- file_name = "tts.mp3"
42
- with open(file_name, 'wb') as wav_file:
43
- decode_string = base64.b64decode(audio)
44
- wav_file.write(decode_string)
45
-
46
- st.audio(file_name, format='audio/mp3')
47
- else:
48
- st.error("Failed to generate speech. Please check your input and try again.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
  gender_options = ['Female', 'Male']
18
  gender = st.selectbox("Select gender", gender_options)
19
 
20
+ # Dictionary mapping language and gender to API URLs
21
+ api_urls = {
22
+ ('Hindi', 'Female'): "https://asr.iitm.ac.in/tts/hindi/female",
23
+ ('Hindi', 'Male'): "https://asr.iitm.ac.in/tts/hindi/male",
24
+ ('English', 'Male'): "https://asr.iitm.ac.in/tts/english/male",
25
+ ('English', 'Female'): "https://asr.iitm.ac.in/tts/english/female",
26
+ ('Malayalam', 'Male'): "https://asr.iitm.ac.in/tts/malayalam/male",
27
+ ('Malayalam', 'Female'): "https://asr.iitm.ac.in/tts/malayalam/female",
28
+ ('Tamil', 'Male'): "https://asr.iitm.ac.in/tts/tamil/male",
29
+ ('Tamil', 'Female'): "https://asr.iitm.ac.in/tts/tamil/female",
30
+ ('Telugu', 'Male'): "https://asr.iitm.ac.in/tts/telugu/male",
31
+ ('Telugu', 'Female'): "https://asr.iitm.ac.in/tts/telugu/female",
32
+ ('Punjabi', 'Male'): "https://asr.iitm.ac.in/tts/punjabi/male",
33
+ ('Punjabi', 'Female'): "https://asr.iitm.ac.in/tts/punjabi/female",
34
+
35
+ ('Urdu', 'Male'): "https://asr.iitm.ac.in/tts/urdu/male",
36
+ ('Urdu', 'Female'): "https://asr.iitm.ac.in/tts/urdu/female",
37
+ ('Marathi', 'Male'): "https://asr.iitm.ac.in/tts/marathi/male",
38
+ ('Marathi', 'Female'): "https://asr.iitm.ac.in/tts/marathi/female",
39
+ ('Gujarati', 'Male'): "https://asr.iitm.ac.in/tts/gujarati/male",
40
+ ('Gujarati', 'Female'): "https://asr.iitm.ac.in/tts/gujarati/female",
41
+
42
+ ('Assamese', 'Male'): "https://asr.iitm.ac.in/tts/assamese/male",
43
+ ('Assamese', 'Female'): "https://asr.iitm.ac.in/tts/assamese/female",
44
+ ('Bengali', 'Male'): "https://asr.iitm.ac.in/tts/bengali/male",
45
+ ('Bengali', 'Female'): "https://asr.iitm.ac.in/tts/bengali/female",
46
+ ('Bodo', 'Male'): "https://asr.iitm.ac.in/tts/bodo/male",
47
+ ('Bodo', 'Female'): "https://asr.iitm.ac.in/tts/bodo/female",
48
+
49
+ ('Kannada', 'Male'): "https://asr.iitm.ac.in/tts/kannada/male",
50
+ ('Kannada', 'Female'): "https://asr.iitm.ac.in/tts/kannada/female",
51
+ ('Manipuri', 'Male'): "https://asr.iitm.ac.in/tts/Manipuri/male",
52
+ ('Manipuri', 'Female'): "https://asr.iitm.ac.in/tts/Manipuri/female",
53
+ ('Odia', 'Male'): "https://asr.iitm.ac.in/tts/odia/male",
54
+ ('Odia', 'Female'): "https://asr.iitm.ac.in/tts/odia/female",
55
+
56
+ ('Rajasthani', 'Male'): "https://asr.iitm.ac.in/tts/rajasthani/male",
57
+ ('Rajasthani', 'Female'): "https://asr.iitm.ac.in/tts/rajasthani/female",
58
+
59
+ # Add more combinations as needed
60
+ }
61
+
62
+ # Get the URL based on language and gender selection
63
+ selected_url = api_urls.get((lang, gender))
64
+
65
+ if selected_url:
66
+ # Button to trigger TTS
67
+ if st.button("Generate Speech"):
68
+ # Prepare payload
69
+ payload = {
70
+ "input": text,
71
+ "gender": gender.lower(),
72
+ "lang": lang.lower(),
73
+ "alpha": 1,
74
+ "segmentwise": "True"
75
+ }
76
+
77
+ # Make API request
78
+ response = requests.post(selected_url, json=payload)
79
+
80
+ # Handle response
81
+ if response.status_code == 200:
82
+ # Decode audio
83
+ audio = response.json()['audio']
84
+ file_name = "tts.mp3"
85
+ with open(file_name, 'wb') as wav_file:
86
+ decode_string = base64.b64decode(audio)
87
+ wav_file.write(decode_string)
88
+
89
+ st.audio(file_name, format='audio/mp3')
90
+ else:
91
+ st.error("Failed to generate speech. Please check your input and try again.")
92
+ else:
93
+ st.error("Selected language and gender combination is not supported.")