corrected edge tts cmd

This commit is contained in:
badmark 2026-08-16 09:50:44 -06:00
parent 4b9cf3cc69
commit e472ef8035
2 changed files with 21 additions and 4 deletions

View file

@ -40,6 +40,17 @@ except ImportError:
def _run_edge_tts(text: str, voice: str, out_wav_path: str): def _run_edge_tts(text: str, voice: str, out_wav_path: str):
"""Synthesize high-quality natural neural voiceover directly via module or CLI.""" """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") tmp_mp3 = out_wav_path.replace(".wav", "_temp.mp3")
if edge_tts is not None: 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) await communicate.save(tmp_mp3)
asyncio.run(_speak()) asyncio.run(_speak())
else: else:
r = subprocess.run([ # Fallback to sys.executable -m edge_tts
"edge-tts", "--voice", voice, "--text", text, "--write-media", tmp_mp3 cmd = [sys.executable, "-m", "edge_tts", "--voice", voice, "--text", text, "--write-media", tmp_mp3]
], capture_output=True, text=True) r = subprocess.run(cmd, capture_output=True, text=True)
if r.returncode != 0: 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([ subprocess.run([
"ffmpeg", "-y", "-i", tmp_mp3, "ffmpeg", "-y", "-i", tmp_mp3,