diff --git a/pipeline/__pycache__/tts_gen.cpython-314.pyc b/pipeline/__pycache__/tts_gen.cpython-314.pyc index 9ff3f7a..d5fe7d7 100644 Binary files a/pipeline/__pycache__/tts_gen.cpython-314.pyc and b/pipeline/__pycache__/tts_gen.cpython-314.pyc differ diff --git a/pipeline/tts_gen.py b/pipeline/tts_gen.py index bbad2c0..8a88f5f 100644 --- a/pipeline/tts_gen.py +++ b/pipeline/tts_gen.py @@ -40,6 +40,17 @@ except ImportError: def _run_edge_tts(text: str, voice: str, out_wav_path: str): """Synthesize high-quality natural neural voiceover directly via module or CLI.""" + global edge_tts + if edge_tts is None: + try: + import edge_tts + except ImportError: + try: + subprocess.run([sys.executable, "-m", "pip", "install", "edge-tts"], check=True, capture_output=True) + import edge_tts + except Exception as e: + logger.warning(f"[TTS] Dynamic edge-tts install failed: {e}") + tmp_mp3 = out_wav_path.replace(".wav", "_temp.mp3") if edge_tts is not None: @@ -48,11 +59,17 @@ def _run_edge_tts(text: str, voice: str, out_wav_path: str): await communicate.save(tmp_mp3) asyncio.run(_speak()) else: - r = subprocess.run([ - "edge-tts", "--voice", voice, "--text", text, "--write-media", tmp_mp3 - ], capture_output=True, text=True) + # Fallback to sys.executable -m edge_tts + cmd = [sys.executable, "-m", "edge_tts", "--voice", voice, "--text", text, "--write-media", tmp_mp3] + r = subprocess.run(cmd, capture_output=True, text=True) if r.returncode != 0: - raise RuntimeError(f"edge-tts CLI error: {r.stderr}") + edge_bin = shutil.which("edge-tts") or os.path.expanduser("~/.local/bin/edge-tts") or os.path.expanduser("~/miniconda3/bin/edge-tts") + if edge_bin and os.path.exists(edge_bin): + r2 = subprocess.run([edge_bin, "--voice", voice, "--text", text, "--write-media", tmp_mp3], capture_output=True, text=True) + if r2.returncode != 0: + raise RuntimeError(f"edge-tts failed: {r.stderr or r2.stderr}") + else: + raise RuntimeError(f"edge-tts execution error: {r.stderr}") subprocess.run([ "ffmpeg", "-y", "-i", tmp_mp3,