|
import streamlit as st |
|
from gtts import gTTS |
|
from io import BytesIO |
|
|
|
|
|
st.markdown(""" |
|
<style> |
|
.stApp { |
|
background-color: #003366; |
|
color: white; |
|
} |
|
|
|
.stButton>button { |
|
color: black; |
|
} |
|
.title-text { |
|
color: white; |
|
} |
|
.title-text { |
|
color: white; |
|
} |
|
.text_area{ |
|
color: white; |
|
} |
|
.st.selectbox{ |
|
color: white; |
|
} |
|
.corner-gif { |
|
position: fixed; |
|
bottom: 10px; |
|
right: 10px; |
|
width: 100px; |
|
height: auto; |
|
z-index: 9999; |
|
} |
|
</style> |
|
""", |
|
unsafe_allow_html=True |
|
) |
|
st.markdown(""" |
|
<img class="corner-gif" src="https://i.gifer.com/PYn.gif"> |
|
""", unsafe_allow_html=True) |
|
|
|
st.markdown('<h1 class="title-text">Текст в речь</h1>', unsafe_allow_html=True) |
|
|
|
|
|
|
|
|
|
def say_text(text, lang='ru'): |
|
tts = gTTS(text=text, lang=lang, slow=False) |
|
fp = BytesIO() |
|
tts.write_to_fp(fp) |
|
fp.seek(0) |
|
return fp.getvalue() |
|
|
|
|
|
text = st.text_area("Введите текст") |
|
|
|
|
|
language = st.selectbox('Выберите язык', ('Русский', 'Английский','Японский','Немецкий', 'Французский')) |
|
|
|
|
|
languages_map = {'Русский': 'ru', 'Английский': 'en','Японский':'ja','Немецкий':'de', 'Французский': 'fr'} |
|
selected_language = languages_map[language] |
|
|
|
|
|
if st.button('Произнести'): |
|
if text: |
|
speech_audio = say_text(text, lang=selected_language) |
|
st.audio(speech_audio, format='audio/mp3', start_time=0) |
|
else: |
|
st.error("Пожалуйста, введите текст.") |