Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
from gtts import gTTS
|
| 3 |
from pydub import AudioSegment
|
| 4 |
-
|
|
|
|
| 5 |
import os
|
| 6 |
|
| 7 |
# νμ 리μ€νΈ
|
|
@@ -13,48 +14,42 @@ absentees = []
|
|
| 13 |
# Streamlit UI
|
| 14 |
st.title("μΆμ νμΈ μμ€ν
")
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
combined = AudioSegment.silent(duration=0) # μμμ μ§§μ 무μ μΆκ°
|
| 19 |
-
for student in students:
|
| 20 |
-
tts = gTTS(student + " νμ")
|
| 21 |
-
tts.save(f"{student}.mp3")
|
| 22 |
-
audio = AudioSegment.from_mp3(f"{student}.mp3")
|
| 23 |
-
combined += audio + AudioSegment.silent(duration=500) # νμ μ΄λ¦ μ¬μ΄μ 0.5μ΄ κ°κ²© μΆκ°
|
| 24 |
-
combined.export("combined_students.wav", format="wav") # WAV νμμΌλ‘ μ μ₯
|
| 25 |
-
return "combined_students.wav"
|
| 26 |
-
|
| 27 |
-
# μ€λμ€ νμΌ μμ±
|
| 28 |
-
audio_file = create_combined_audio_file(student_list)
|
| 29 |
-
|
| 30 |
-
# μμ± μΈμμ μν ν¨μ
|
| 31 |
-
def recognize_audio(file):
|
| 32 |
-
recognizer = sr.Recognizer()
|
| 33 |
-
with sr.AudioFile(file) as source:
|
| 34 |
-
audio = recognizer.record(source)
|
| 35 |
-
try:
|
| 36 |
-
return recognizer.recognize_google(audio, language="ko-KR")
|
| 37 |
-
except sr.UnknownValueError:
|
| 38 |
-
return "μΈμ λΆκ°"
|
| 39 |
-
except sr.RequestError:
|
| 40 |
-
return "STT μλΉμ€ μμ² μ€ν¨"
|
| 41 |
|
| 42 |
-
# μ€λμ€
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
# κ²°μ μ²λ¦¬
|
| 50 |
-
if
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
# κ²°μμ 리μ€νΈ 보μ¬μ£ΌκΈ°
|
| 60 |
st.subheader("κ²°μμ 리μ€νΈ")
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
from gtts import gTTS
|
| 3 |
from pydub import AudioSegment
|
| 4 |
+
from pydub.playback import play
|
| 5 |
+
import tempfile
|
| 6 |
import os
|
| 7 |
|
| 8 |
# νμ 리μ€νΈ
|
|
|
|
| 14 |
# Streamlit UI
|
| 15 |
st.title("μΆμ νμΈ μμ€ν
")
|
| 16 |
|
| 17 |
+
if 'current_index' not in st.session_state:
|
| 18 |
+
st.session_state.current_index = 0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
|
| 20 |
+
# μ€λμ€ νμΌ μμ± ν¨μ
|
| 21 |
+
def create_audio_for_student(student):
|
| 22 |
+
tts = gTTS(student + " νμ")
|
| 23 |
+
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.mp3')
|
| 24 |
+
tts.save(temp_file.name)
|
| 25 |
+
return temp_file.name
|
| 26 |
+
|
| 27 |
+
# νμ¬ νμ μ΄λ¦ κ°μ Έμ€κΈ°
|
| 28 |
+
current_student = student_list[st.session_state.current_index]
|
| 29 |
+
|
| 30 |
+
# νμ μ΄λ¦ λΆλ¬μ€κΈ°
|
| 31 |
+
if st.button("λ€μ νμ"):
|
| 32 |
+
# νμ¬ νμμ μ΄λ¦μ μ€λμ€λ‘ μ¬μ
|
| 33 |
+
audio_file = create_audio_for_student(current_student)
|
| 34 |
+
audio = AudioSegment.from_mp3(audio_file)
|
| 35 |
+
play(audio)
|
| 36 |
+
os.remove(audio_file) # μμ νμΌ μμ
|
| 37 |
+
|
| 38 |
+
# νλ©΄μ νμ¬ νμ μ΄λ¦ νμ
|
| 39 |
+
st.subheader(f"νμ¬ νμ: {current_student}")
|
| 40 |
|
| 41 |
# κ²°μ μ²λ¦¬
|
| 42 |
+
if st.radio(f"{current_student} μΆμ μ¬λΆ", ("μΆμ", "κ²°μ")) == "κ²°μ":
|
| 43 |
+
absentees.append(current_student)
|
| 44 |
+
with open("absentees.txt", "a") as f:
|
| 45 |
+
f.write(f"{current_student}\n")
|
| 46 |
+
st.success(f"{current_student}κ° κ²°μμλ‘ λ±λ‘λμμ΅λλ€.")
|
| 47 |
+
|
| 48 |
+
# λ€μ νμμΌλ‘ μΈλ±μ€ μ΄λ
|
| 49 |
+
if st.session_state.current_index < len(student_list) - 1:
|
| 50 |
+
st.session_state.current_index += 1
|
| 51 |
+
else:
|
| 52 |
+
st.write("λͺ¨λ νμμ μ΄λ¦μ λΆλ μ΅λλ€.")
|
| 53 |
|
| 54 |
# κ²°μμ 리μ€νΈ 보μ¬μ£ΌκΈ°
|
| 55 |
st.subheader("κ²°μμ 리μ€νΈ")
|