tts_demo / app.py
telee's picture
Upload 2 files
f80d298
raw
history blame contribute delete
925 Bytes
import streamlit as st
from gtts import gTTS
from io import BytesIO
LANG = "en"
# https://gtts.readthedocs.io/en/latest/
#
def tts_gtts(text):
mp3_fp = BytesIO()
tts = gTTS(text, lang=LANG)
tts.write_to_fp(mp3_fp)
return mp3_fp
def pronounce(text, gender=None):
if len(text) > 0:
data1 = tts_gtts(text)
st.text('gTTS (gender not supported):')
st.audio(data1, format="audio/wav", start_time=0)
def main():
st.title('TTS Demo')
# uploaded_file = st.file_uploader("Upload a recording of you saying the text in .wav format")
# if uploaded_file is not None:
# pass
text_input = st.text_input("", value="Input the text you are saying in your recording.")
gender_input = st.radio("Gender", ["M", "F"], captions=["", ""], horizontal=True)
if st.button("Pronounce"):
pronounce(text_input, gender_input)
if __name__ == "__main__":
main()