Update app.py
Browse files
app.py
CHANGED
@@ -19,6 +19,9 @@ from langchain.memory import StreamlitChatMessageHistory
|
|
19 |
from gtts import gTTS
|
20 |
from IPython.display import Audio, display
|
21 |
|
|
|
|
|
|
|
22 |
#์ฌ์ดํธ ๊ด๋ จ ํจ์
|
23 |
def main():
|
24 |
st.set_page_config(
|
@@ -79,6 +82,19 @@ def main():
|
|
79 |
st.session_state.chat_history = result['chat_history']
|
80 |
response = result['answer']
|
81 |
source_documents = result['source_documents']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
82 |
|
83 |
st.markdown(response)
|
84 |
with st.expander("์ฐธ๊ณ ๋ฌธ์ ํ์ธ"):
|
|
|
19 |
from gtts import gTTS
|
20 |
from IPython.display import Audio, display
|
21 |
|
22 |
+
from pydub import AudioSegment
|
23 |
+
import simpleaudio as sa
|
24 |
+
|
25 |
#์ฌ์ดํธ ๊ด๋ จ ํจ์
|
26 |
def main():
|
27 |
st.set_page_config(
|
|
|
82 |
st.session_state.chat_history = result['chat_history']
|
83 |
response = result['answer']
|
84 |
source_documents = result['source_documents']
|
85 |
+
|
86 |
+
# Text-to-Speech ๋ณํ
|
87 |
+
tts = gTTS(text=response, lang='ko')
|
88 |
+
tts.save('output.mp3') # ์์ฑ ํ์ผ ์ ์ฅ
|
89 |
+
|
90 |
+
# ์์ฑ ํ์ผ ๋ก๋
|
91 |
+
audio = AudioSegment.from_file("output.mp3")
|
92 |
+
audio.export("temp.wav", format="wav") # wav ํ์์ผ๋ก ๋ณํ
|
93 |
+
|
94 |
+
# ์์ฑ ์ฌ์
|
95 |
+
wave_obj = sa.WaveObject.from_wave_file("temp.wav")
|
96 |
+
play_obj = wave_obj.play()
|
97 |
+
play_obj.wait_done()
|
98 |
|
99 |
st.markdown(response)
|
100 |
with st.expander("์ฐธ๊ณ ๋ฌธ์ ํ์ธ"):
|