diff options
Diffstat (limited to 'converter/tts.py')
| -rw-r--r-- | converter/tts.py | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/converter/tts.py b/converter/tts.py index ac47ecb..c3a4b81 100644 --- a/converter/tts.py +++ b/converter/tts.py @@ -36,6 +36,7 @@ class QwenTTSClient: # ------------------------------------------------------------------ def _connect(self) -> None: + api_url = config.VOICE_CLONE_API_URL if self.voice_mode == "voice_clone" else config.QWEN_API_URL try: if self.voice_mode == "voice_clone": # Voice clone uses the Base-model demo, which is a separate server @@ -47,17 +48,12 @@ class QwenTTSClient: self._init_client(config.QWEN_API_URL, clone=False) print("[OK] Connected to Qwen API") except Exception as exc: - api_url = config.VOICE_CLONE_API_URL if self.voice_mode == "voice_clone" else config.QWEN_API_URL - print("[ERROR] Qwen API initialization failed!") - print(f"API endpoint: {api_url}") - print("Make sure:") - print("1. Qwen Gradio server is running") - print("2. The server is accessible at the configured URL") - print("3. The endpoint URL is correct") - print("4. Your installed Qwen3-TTS version matches this converter's API expectations") - print(" (voice clone requires the Base-model demo: Qwen/Qwen3-TTS-12Hz-1.7B-Base)") - print(f"Error: {exc}") - sys.exit(1) + raise RuntimeError( + f"Qwen API initialization failed at {api_url}: {exc}. " + "Make sure the Qwen Gradio server is running and reachable, and that your " + "installed Qwen3-TTS version matches this converter's API expectations " + "(voice clone requires the Base-model demo: Qwen/Qwen3-TTS-12Hz-1.7B-Base)." + ) from exc def _resolve_reference_text(self) -> None: """Resolve the reference transcript: explicit text, then local @@ -172,15 +168,20 @@ class QwenTTSClient: else: raise ValueError(f"Unknown voice mode: {self.voice_mode}") - if not result or len(result) < 2: - raise RuntimeError("Qwen API returned invalid result") + if not isinstance(result, (tuple, list)) or not result: + raise RuntimeError("Qwen API returned an invalid result") audio_path = result[0] # First element is the audio file path - if not audio_path or not Path(audio_path).exists(): + if not isinstance(audio_path, (str, Path)) or not audio_path: + raise RuntimeError("Qwen API did not return an audio file path") + + source = Path(audio_path) + if not source.exists(): raise RuntimeError(f"Generated audio file not found: {audio_path}") - output_path = config.CHUNKS_FOLDER / f"chunk_{chunk_num:04d}.wav" - shutil.copy2(audio_path, output_path) + suffix = source.suffix or ".wav" + output_path = config.CHUNKS_FOLDER / f"chunk_{chunk_num:04d}{suffix}" + shutil.copy2(source, output_path) logger.debug("Chunk %d generated successfully", chunk_num) return str(output_path) |
