Spaces:
Runtime error
Runtime error
ego commited on
Commit ·
19edd1b
1
Parent(s): 816fcde
Fix TTS: use correct TTSService class, add fallback when TTS returns None
Browse files- core/models.py +14 -11
- core/podcast.py +3 -1
core/models.py
CHANGED
|
@@ -45,7 +45,7 @@ def generate_podcast_audio(script_text: str):
|
|
| 45 |
|
| 46 |
try:
|
| 47 |
from riva.client import Auth
|
| 48 |
-
from riva.client import
|
| 49 |
|
| 50 |
# Setup authentication for NVIDIA hosted Riva TTS
|
| 51 |
metadata = [
|
|
@@ -53,8 +53,8 @@ def generate_podcast_audio(script_text: str):
|
|
| 53 |
("authorization", f"Bearer {api_key}")
|
| 54 |
]
|
| 55 |
|
| 56 |
-
auth = Auth(
|
| 57 |
-
tts_service =
|
| 58 |
|
| 59 |
# Remove speaker labels for single-voice synthesis
|
| 60 |
lines = script_text.split('\n')
|
|
@@ -71,18 +71,21 @@ def generate_podcast_audio(script_text: str):
|
|
| 71 |
|
| 72 |
clean_text = ' '.join(clean_lines)
|
| 73 |
|
| 74 |
-
# Call TTS API
|
| 75 |
-
|
| 76 |
-
text
|
| 77 |
-
language_code
|
| 78 |
-
encoding
|
| 79 |
-
sample_rate_hz
|
| 80 |
-
voice_name
|
| 81 |
-
|
|
|
|
| 82 |
|
| 83 |
# resp.audio contains PCM bytes (16-bit, mono)
|
| 84 |
return resp.audio
|
| 85 |
|
| 86 |
except Exception as e:
|
| 87 |
print(f"NVIDIA Riva TTS failed: {e}")
|
|
|
|
|
|
|
| 88 |
return None
|
|
|
|
| 45 |
|
| 46 |
try:
|
| 47 |
from riva.client import Auth
|
| 48 |
+
from riva.client import TTSService
|
| 49 |
|
| 50 |
# Setup authentication for NVIDIA hosted Riva TTS
|
| 51 |
metadata = [
|
|
|
|
| 53 |
("authorization", f"Bearer {api_key}")
|
| 54 |
]
|
| 55 |
|
| 56 |
+
auth = Auth(None, True, "grpc.nvcf.nvidia.com:443", metadata)
|
| 57 |
+
tts_service = TTSService(auth)
|
| 58 |
|
| 59 |
# Remove speaker labels for single-voice synthesis
|
| 60 |
lines = script_text.split('\n')
|
|
|
|
| 71 |
|
| 72 |
clean_text = ' '.join(clean_lines)
|
| 73 |
|
| 74 |
+
# Call TTS API - use dict-style args as expected by TTSService.synthesize()
|
| 75 |
+
req = {
|
| 76 |
+
"text": clean_text,
|
| 77 |
+
"language_code": "en-US",
|
| 78 |
+
"encoding": 1, # LINEAR_PCM
|
| 79 |
+
"sample_rate_hz": 22050, # Magpie TTS sample rate
|
| 80 |
+
"voice_name": "Magpie-Multilingual.EN-US.Aria"
|
| 81 |
+
}
|
| 82 |
+
resp = tts_service.synthesize(**req)
|
| 83 |
|
| 84 |
# resp.audio contains PCM bytes (16-bit, mono)
|
| 85 |
return resp.audio
|
| 86 |
|
| 87 |
except Exception as e:
|
| 88 |
print(f"NVIDIA Riva TTS failed: {e}")
|
| 89 |
+
import traceback
|
| 90 |
+
traceback.print_exc()
|
| 91 |
return None
|
core/podcast.py
CHANGED
|
@@ -31,7 +31,9 @@ class PodcastGenerator:
|
|
| 31 |
self.wave_file(tmp_path, data, rate=22050)
|
| 32 |
return tmp_path
|
| 33 |
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
|
| 36 |
except Exception as e:
|
| 37 |
print(f"NVIDIA Riva TTS failed: {e}. Falling back to gTTS.")
|
|
|
|
| 31 |
self.wave_file(tmp_path, data, rate=22050)
|
| 32 |
return tmp_path
|
| 33 |
|
| 34 |
+
# If we get here, data is None - log and fallback
|
| 35 |
+
print("NVIDIA Riva TTS returned None, falling back to gTTS.")
|
| 36 |
+
raise Exception("TTS returned None")
|
| 37 |
|
| 38 |
except Exception as e:
|
| 39 |
print(f"NVIDIA Riva TTS failed: {e}. Falling back to gTTS.")
|