utkarsh2299
commited on
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,89 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import json
|
4 |
+
import base64
|
5 |
+
|
6 |
+
# Streamlit UI
|
7 |
+
st.title("TTS")
|
8 |
+
|
9 |
+
# User inputs
|
10 |
+
text = st.text_area("Enter the text to convert to speech")
|
11 |
+
|
12 |
+
# Language selection
|
13 |
+
lang_options = ['Hindi', 'Malayalam', 'Manipuri', 'Marathi', 'Kannada', 'English', 'Assamese', 'Tamil', 'Odia', 'Rajasthani', 'Telugu', 'Bengali', 'Gujarati']
|
14 |
+
lang = st.selectbox("Select language", lang_options)
|
15 |
+
|
16 |
+
# Gender selection
|
17 |
+
gender_options = ['Male', 'Female']
|
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 |
+
audio_bytes = base64.b64decode(audio)
|
85 |
+
st.audio(audio_bytes, format='audio/mp3')
|
86 |
+
else:
|
87 |
+
st.error("Failed to generate speech. Please check your input and try again.")
|
88 |
+
else:
|
89 |
+
st.error("Selected language and gender combination is not supported.")
|