Spaces:
Runtime error
Runtime error
Create api.py
Browse files
api.py
ADDED
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import requests
|
3 |
+
import json
|
4 |
+
import base64
|
5 |
+
|
6 |
+
# Streamlit UI
|
7 |
+
st.title("TTS IITM Speech Lab")
|
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 = ['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 = "http://10.24.6.165:2001/" # 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.")
|