parvezalmuqtadir commited on
Commit
f85fb1d
1 Parent(s): 720d97e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -2
app.py CHANGED
@@ -96,10 +96,15 @@ def generate_speech(text):
96
  play_sound("output.mp3")
97
 
98
  def play_sound(file_path):
99
- pygame.mixer.init()
 
 
 
 
 
100
  pygame.mixer.music.load(file_path)
101
  pygame.mixer.music.play()
102
- while pygame.mixer.music.get_busy(): # Wait for audio to finish playing
103
  pygame.time.Clock().tick(10)
104
 
105
  # Additional cleanup to remove temporary files
 
96
  play_sound("output.mp3")
97
 
98
  def play_sound(file_path):
99
+ try:
100
+ pygame.mixer.init()
101
+ except pygame.error:
102
+ print("Unable to initialize audio device. Audio playback will be disabled.")
103
+ return
104
+
105
  pygame.mixer.music.load(file_path)
106
  pygame.mixer.music.play()
107
+ while pygame.mixer.music.get_busy():
108
  pygame.time.Clock().tick(10)
109
 
110
  # Additional cleanup to remove temporary files