Spaces:
Runtime error
Runtime error
Commit Β·
504b344
1
Parent(s): 4ddb074
changes
Browse files- 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
"""
|