File size: 1,337 Bytes
81d0661
 
 
c5853a8
81d0661
e4e4988
81d0661
 
 
 
 
 
c5853a8
81d0661
e4e4988
 
 
 
 
 
 
81d0661
 
c5853a8
 
 
 
 
 
 
 
e4e4988
 
 
 
c5853a8
 
 
 
e4e4988
c5853a8
e4e4988
c5853a8
 
 
e4e4988
c5853a8
e4e4988
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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
49
50
import pandas as pd
import streamlit as st
from gtts import gTTS
import io
import os
import random

# Wczytanie danych
df = pd.read_csv(r'dane.tsv', sep='\t', header=None)[[1, 3]]
df.columns = ['W艂oski', 'Polski']

# Tytu艂 aplikacji
st.title("eataly")

# Inicjacja stanu sesji
if 'index' not in st.session_state:
    st.session_state.index = random.randint(0, len(df) - 1)

# Funkcja do losowania nowego zdania
def random_sentence():
    st.session_state.index = random.randint(0, len(df) - 1)

# Funkcja do odtwarzania tekstu jako mowy
def speak_text(text, lang):
    tts = gTTS(text=text, lang=lang)
    fp = io.BytesIO()
    tts.write_to_fp(fp)
    fp.seek(0)
    
    return fp

# Przycisk do losowania nowego zdania
if st.button("Losuj nowe zdanie"):
    random_sentence()

# Przyciski do odtwarzania wymowy obok siebie
col1, col2 = st.columns(2)

with col1:
    st.subheader(df['W艂oski'][st.session_state.index])
    if st.button("Odtw贸rz wymow臋 po w艂osku"):
        audio_data = speak_text(df['W艂oski'][st.session_state.index], 'it')
        st.audio(audio_data, format='audio/mp3')

with col2:
    st.subheader(df['Polski'][st.session_state.index])
    if st.button("Odtw贸rz wymow臋 po polsku"):
        audio_data = speak_text(df['Polski'][st.session_state.index], 'pl')
        st.audio(audio_data, format='audio/mp3')