Spaces:
Runtime error
Runtime error
Update app.py
Browse files
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 |
-
#
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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.")
|