danny042 commited on
Commit
3341488
โ€ข
1 Parent(s): 6c0ef7b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -0
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("์ฐธ๊ณ  ๋ฌธ์„œ ํ™•์ธ"):