import streamlit as st from gradio_client import Client from st_audiorec import st_audiorec from gtts import gTTS import os # ... (previous code remains unchanged) # Function to convert text to speech def text_to_speech(text, language='en', filename='output.mp3'): # Create a gTTS object tts = gTTS(text=text, lang=language, slow=False) # Save the audio file tts.save(filename) # Play the audio file os.system(f'start {filename}') # This works on Windows. For other OS, you might need a different command. # ... (previous code remains unchanged) # React to user input if prompt := textinput: # Display user message in chat message container st.chat_message("human", avatar="💬: ").markdown(prompt) # Add user message to chat history st.session_state.messages.append({"role": "human", "content": prompt}) # Update the global response variable response = predict(message=prompt) # Display assistant response in chat message container with st.chat_message("assistant", avatar='🦙'): st.markdown(response) # Add assistant response to chat history st.session_state.messages.append({"role": "assistant", "content": response}) # Convert response to audio text_to_speech(response) # Call text_to_speech after getting the response