ChAbhishek28 commited on
Commit
504b344
Β·
1 Parent(s): 4ddb074
Files changed (1) hide show
  1. groq_voice_service.py +32 -1
groq_voice_service.py CHANGED
@@ -96,6 +96,8 @@ class GroqVoiceService:
96
  # Use default voice for the configured language if no voice specified
97
  if voice is None:
98
  voice = self._get_default_voice()
 
 
99
 
100
  try:
101
  if self.tts_provider == "edge-tts":
@@ -106,13 +108,42 @@ class GroqVoiceService:
106
  async for chunk in communicate.stream():
107
  if chunk["type"] == "audio":
108
  audio_data += chunk["data"]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
109
  return audio_data
110
  elif self.tts_provider == "murf":
111
  audio_data = await self._murf_tts(text, voice)
112
  return audio_data
113
  except Exception as e:
114
  logger.error(f"❌ TTS Error: {e}")
115
- return None
 
 
 
 
 
 
 
 
 
 
 
 
116
 
117
  async def _murf_tts(self, text: str, voice: str = None) -> Optional[bytes]:
118
  """
 
96
  # Use default voice for the configured language if no voice specified
97
  if voice is None:
98
  voice = self._get_default_voice()
99
+
100
+ logger.info(f"πŸ”Š Generating TTS with voice: {voice}, language: {self.language}")
101
 
102
  try:
103
  if self.tts_provider == "edge-tts":
 
108
  async for chunk in communicate.stream():
109
  if chunk["type"] == "audio":
110
  audio_data += chunk["data"]
111
+
112
+ # Validate audio data was received
113
+ if not audio_data:
114
+ logger.warning(f"⚠️ No audio generated from TTS for voice: {voice}")
115
+ # Try fallback voice
116
+ fallback_voice = "en-US-AriaNeural"
117
+ logger.info(f"πŸ”„ Retrying with fallback voice: {fallback_voice}")
118
+ communicate = edge_tts.Communicate(text, fallback_voice, rate=f"{int((self.voice_speed - 1) * 100):+d}%")
119
+ audio_data = b""
120
+ async for chunk in communicate.stream():
121
+ if chunk["type"] == "audio":
122
+ audio_data += chunk["data"]
123
+
124
+ if not audio_data:
125
+ logger.error("❌ Fallback TTS also failed")
126
+ return None
127
+
128
  return audio_data
129
  elif self.tts_provider == "murf":
130
  audio_data = await self._murf_tts(text, voice)
131
  return audio_data
132
  except Exception as e:
133
  logger.error(f"❌ TTS Error: {e}")
134
+ # Try one last fallback with basic US English voice
135
+ try:
136
+ import edge_tts
137
+ logger.info("πŸ”„ Attempting emergency fallback TTS")
138
+ communicate = edge_tts.Communicate(text, "en-US-AriaNeural")
139
+ audio_data = b""
140
+ async for chunk in communicate.stream():
141
+ if chunk["type"] == "audio":
142
+ audio_data += chunk["data"]
143
+ return audio_data if audio_data else None
144
+ except:
145
+ logger.error("❌ All TTS attempts failed")
146
+ return None
147
 
148
  async def _murf_tts(self, text: str, voice: str = None) -> Optional[bytes]:
149
  """