mohAhmad commited on
Commit
c2e34cb
β€’
1 Parent(s): 642c2b0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -4
app.py CHANGED
@@ -104,8 +104,18 @@ elif options == "Phoneme Practice":
104
  transcription = phoneme_processor.batch_decode(predicted_ids)
105
  st.write(f"Transcription: {transcription[0]}")
106
 
 
 
 
 
 
 
 
 
 
 
107
  # Guided Meditation for Kids
108
- elif options == "Guided Meditation":
109
  st.header("πŸ§˜β€β™‚οΈ Guided Meditation for Kids")
110
  st.write("Relax and listen to a calming meditation.")
111
 
@@ -115,9 +125,14 @@ elif options == "Guided Meditation":
115
  with st.spinner("Playing meditation audio..."):
116
  tts_engine = initialize_tts()
117
  if tts_engine:
118
- tts_engine.save_to_file(meditation_text, 'meditation.mp3')
119
- tts_engine.runAndWait()
120
- st.audio('meditation.mp3', format='audio/mp3')
 
 
 
 
 
121
 
122
  # Footer
123
  st.markdown("<footer style='text-align: center; padding-top: 20px;'>Made with ❀️ for Kids by ChiliDron Team</footer>", unsafe_allow_html=True)
 
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")
120
  st.write("Relax and listen to a calming meditation.")
121
 
 
125
  with st.spinner("Playing meditation audio..."):
126
  tts_engine = initialize_tts()
127
  if tts_engine:
128
+ try:
129
+ tts_engine.save_to_file(meditation_text, 'meditation.mp3')
130
+ tts_engine.runAndWait()
131
+ st.audio('meditation.mp3', format='audio/mp3')
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)