Update app.py
Browse files
app.py
CHANGED
@@ -4,6 +4,8 @@ import pyttsx3
|
|
4 |
import random
|
5 |
import torchaudio
|
6 |
import torch # Add this import statement to fix the NameError
|
|
|
|
|
7 |
|
8 |
# Set up the app
|
9 |
st.set_page_config(page_title="ChiliDron", layout="wide", page_icon="π¨")
|
@@ -104,16 +106,6 @@ elif options == "Phoneme Practice":
|
|
104 |
transcription = phoneme_processor.batch_decode(predicted_ids)
|
105 |
st.write(f"Transcription: {transcription[0]}")
|
106 |
|
107 |
-
# Initialize TTS engine with more robust error handling
|
108 |
-
def initialize_tts():
|
109 |
-
try:
|
110 |
-
# Specify a driver if needed: 'sapi5' for Windows, 'espeak' for Linux
|
111 |
-
engine = pyttsx3.init(driverName=None) # Try 'sapi5', 'espeak', or 'nsss' (macOS)
|
112 |
-
return engine
|
113 |
-
except Exception as e:
|
114 |
-
st.error(f"Error initializing text-to-speech engine: {e}")
|
115 |
-
return None
|
116 |
-
|
117 |
# Guided Meditation for Kids
|
118 |
if options == "Guided Meditation":
|
119 |
st.header("π§ββοΈ Guided Meditation for Kids")
|
@@ -122,17 +114,13 @@ if options == "Guided Meditation":
|
|
122 |
meditation_text = "Close your eyes and take a deep breath. Imagine you are in a peaceful forest, with birds singing and leaves rustling in the wind."
|
123 |
|
124 |
if st.button("Play Meditation"):
|
125 |
-
with st.spinner("
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
except Exception as e:
|
133 |
-
st.error(f"Error during TTS operation: {e}")
|
134 |
-
else:
|
135 |
-
st.error("Failed to initialize the text-to-speech engine.")
|
136 |
|
137 |
# Footer
|
138 |
st.markdown("<footer style='text-align: center; padding-top: 20px;'>Made with β€οΈ for Kids by ChiliDron Team</footer>", unsafe_allow_html=True)
|
|
|
4 |
import random
|
5 |
import torchaudio
|
6 |
import torch # Add this import statement to fix the NameError
|
7 |
+
from gtts import gTTS
|
8 |
+
import os
|
9 |
|
10 |
# Set up the app
|
11 |
st.set_page_config(page_title="ChiliDron", layout="wide", page_icon="π¨")
|
|
|
106 |
transcription = phoneme_processor.batch_decode(predicted_ids)
|
107 |
st.write(f"Transcription: {transcription[0]}")
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
# Guided Meditation for Kids
|
110 |
if options == "Guided Meditation":
|
111 |
st.header("π§ββοΈ Guided Meditation for Kids")
|
|
|
114 |
meditation_text = "Close your eyes and take a deep breath. Imagine you are in a peaceful forest, with birds singing and leaves rustling in the wind."
|
115 |
|
116 |
if st.button("Play Meditation"):
|
117 |
+
with st.spinner("Generating meditation audio..."):
|
118 |
+
try:
|
119 |
+
tts = gTTS(text=meditation_text, lang='en')
|
120 |
+
tts.save('meditation.mp3')
|
121 |
+
st.audio('meditation.mp3', format='audio/mp3')
|
122 |
+
except Exception as e:
|
123 |
+
st.error(f"Error generating or playing the audio: {e}")
|
|
|
|
|
|
|
|
|
124 |
|
125 |
# Footer
|
126 |
st.markdown("<footer style='text-align: center; padding-top: 20px;'>Made with β€οΈ for Kids by ChiliDron Team</footer>", unsafe_allow_html=True)
|