AchyuthGamer commited on
Commit
bfaeb19
1 Parent(s): 12071d0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -0
app.py CHANGED
@@ -1,6 +1,9 @@
1
  import streamlit as st
2
  from gradio_client import Client
3
  from st_audiorec import st_audiorec
 
 
 
4
 
5
 
6
  # Constants
@@ -106,6 +109,19 @@ if prompt := textinput:
106
  st.markdown(response)
107
  # Add assistant response to chat history
108
  st.session_state.messages.append({"role": "assistant", "content": response})
 
 
 
 
 
 
 
 
 
 
 
 
 
109
 
110
 
111
 
 
1
  import streamlit as st
2
  from gradio_client import Client
3
  from st_audiorec import st_audiorec
4
+ from gtts import gTTS
5
+ import os
6
+
7
 
8
 
9
  # Constants
 
109
  st.markdown(response)
110
  # Add assistant response to chat history
111
  st.session_state.messages.append({"role": "assistant", "content": response})
112
+
113
+ def text_to_speech(text, language='en', filename='output.mp3'):
114
+ # Create a gTTS object
115
+ tts = gTTS(text=text, lang=language, slow=False)
116
+
117
+ # Save the audio file
118
+ tts.save(filename)
119
+
120
+ # Play the audio file
121
+ os.system(f'start {filename}') # This works on Windows. For other OS, you might need a different command.
122
+
123
+ # Example usage
124
+ text_to_speech(response)
125
 
126
 
127